{"id":28614200,"url":"https://github.com/perldancer/dancer-plugin-adapter","last_synced_at":"2026-05-30T22:31:51.620Z","repository":{"id":5946356,"uuid":"7167102","full_name":"PerlDancer/dancer-plugin-adapter","owner":"PerlDancer","description":"Wrap any simple class for use with Dancer","archived":false,"fork":false,"pushed_at":"2013-02-20T10:19:22.000Z","size":129,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-12T01:13:29.777Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://metacpan.org/author/DAGOLDEN","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"n33/skel","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerlDancer.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":"CONTRIBUTING","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-14T15:04:30.000Z","updated_at":"2019-09-24T13:21:37.000Z","dependencies_parsed_at":"2022-08-19T13:11:28.289Z","dependency_job_id":null,"html_url":"https://github.com/PerlDancer/dancer-plugin-adapter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/PerlDancer/dancer-plugin-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerlDancer","download_url":"https://codeload.github.com/PerlDancer/dancer-plugin-adapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-adapter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262026907,"owners_count":23246951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-12T01:13:23.765Z","updated_at":"2025-12-12T02:40:48.294Z","avatar_url":"https://github.com/PerlDancer.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=pod\n\n=head1 NAME\n\nDancer::Plugin::Adapter - Wrap any simple class as a service for Dancer\n\n=head1 VERSION\n\nversion 0.004\n\n=head1 SYNOPSIS\n\n  # in config.yml\n\n  plugins:\n    Adapter:\n      ua:\n        class: HTTP::Tiny\n        scope: request\n        options:\n          max_redirect: 3\n\n  # in your app\n\n  use Dancer::Plugin::Adapter;\n\n  get '/proxy/:url' =\u003e sub {\n    my $res = service('ua')-\u003eget( params-\u003e{'url'} );\n    if ( $res-\u003e{success} ) {\n      return $res-\u003e{content};\n    }\n    else {\n      template 'error' =\u003e { response =\u003e $res };\n    }\n  };\n\n=head1 DESCRIPTION\n\nThe problem: you want to use some perl class in your Dancer app, but there's\nno plugin for it.\n\nThe solution: as long as the class needs only static data to construct an\nobject, then C\u003cDancer::Plugin::Adaptor\u003e can do the wrapping for you.  Think\nof it as a \"just-in-time\" plugin (or maybe a poor-man's L\u003cBread::Board\u003e).\n\nHere's another example: you want to send emails via\nL\u003cPostmark|http://postmarkapp.com\u003e using L\u003cWWW::Postmark\u003e.\n\nIn your config.yml, you put this:\n\n  plugins:\n    Adapter:\n      postmark:\n        class: WWW::Postmark\n        scope: singleton\n        options: POSTMARK_API_TEST\n\nIn your production config.yml, you can replace 'POSTMARK_API_TEST' with your\nreal Postmark API key.\n\nThen, in your application, here's how you use it:\n\n    get '/' =\u003e sub {\n      eval {\n        service(\"postmark\")-\u003esend(\n          from    =\u003e 'me@domain.tld',\n          to      =\u003e 'you@domain.tld, them@domain.tld',\n          subject =\u003e 'an email message',\n          body    =\u003e \"hi guys, what's up?\"\n        );\n      };\n\n      return $@ ? \"Error: $@\" : \"Mail sent\";\n    };\n\nC\u003cDancer::Plugin::Adapter\u003e takes care of constructing and caching the\nL\u003cWWW::Postmark\u003e object based on the configuration data, and lets you access\nthe object with the C\u003cservice()\u003e function.\n\n=for Pod::Coverage method_names_here\n\n=head1 CONFIGURATION\n\nOne or more objects are defined by C\u003c\u003c NAME =\u003e HASHREF \u003e\u003e pairs.  The hash\nreference for each NAME must contain a 'class' key, whose value is the class\nto wrap.\n\nThe 'scope' key determines how long the generated object persists.  The choice\nof scope will depend on whether the object holds onto any state that should not\nlast across requests or users.  The following scope values are allowed:\n\n=over 4\n\n=item *\n\nC\u003crequest\u003e -- (default) the object persists in the C\u003cvars\u003e hash for the duration of the request\n\n=item *\n\nC\u003csingleton\u003e -- the objects persists in a private, lexical hash for the duration of the process\n\n=item *\n\nC\u003csession\u003e -- the object persists in the C\u003csession\u003e hash for the duration of the session\n\n=item *\n\nC\u003cnone\u003e -- the object is not cached; a fresh object is created on each call\n\n=back\n\nIf the hash reference contains an 'options' key, its value will be dereferenced\n(if it is a hash or array reference) and passed to C\u003cnew()\u003e when the object is\ncreated.  Note that if the class requires a reference for the constructor,\nyou have to wrap it in an extra array.  E.g.\n\n  # config.yml:\n  plugins:\n    Adapter:\n      foo:\n        class: Foo::Bar\n        scope: request \n        options:\n          -\n            wibble: wobble\n            biff: boff\n\n  # constructor called as:\n  Foo::Bar-\u003enew( { wibble =\u003e wobble, biff =\u003e boff } );\n\nIf the class does not use 'new' as the name of its constructor, an alternate\ncan be specified with the 'constructor' key.\n\n  # config.yml:\n  plugins:\n    Adapter:\n      tmpdir:\n        class: File::Temp\n        constructor: newdir\n\n  # constructor called as:\n  File::Temp-\u003enewdir()\n\nWhen caching under C\u003crequest\u003e or C\u003csession\u003e scope, Dancer::Plugin::Adaptor uses\nthe key C\u003c_dpa\u003e in the C\u003cvars\u003e or C\u003csession\u003e hash, respectively.\n\n=head1 USAGE\n\n=head2 service\n\n  $object = service($name);\n\nThis function returns the object corresponding to the name defined in the\nconfiguration file.  The object is created on demand and may be cached for\nfuture use based on its C\u003cscope\u003e configuration option.\n\n=head1 SEE ALSO\n\n=over 4\n\n=item *\n\nL\u003cDancer\u003e\n\n=item *\n\nL\u003cDancer::Plugin\u003e\n\n=back\n\n=head1 ACKNOWLEDGMENTS\n\nThank you to Matt S. Trout for suggesting the 'scope' controls.\n\n=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan\n\n=head1 SUPPORT\n\n=head2 Bugs / Feature Requests\n\nPlease report any bugs or feature requests through the issue tracker\nat L\u003chttps://github.com/dagolden/dancer-plugin-adapter/issues\u003e.\nYou will be notified automatically of any progress on your issue.\n\n=head2 Source Code\n\nThis is open source software.  The code repository is available for\npublic review and contribution under the terms of the license.\n\nL\u003chttps://github.com/dagolden/dancer-plugin-adapter\u003e\n\n  git clone git://github.com/dagolden/dancer-plugin-adapter.git\n\n=head1 AUTHOR\n\nDavid Golden \u003cdagolden@cpan.org\u003e\n\n=head1 COPYRIGHT AND LICENSE\n\nThis software is Copyright (c) 2012 by David Golden.\n\nThis is free software, licensed under:\n\n  The Apache License, Version 2.0, January 2004\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperldancer%2Fdancer-plugin-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperldancer%2Fdancer-plugin-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperldancer%2Fdancer-plugin-adapter/lists"}