Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'patch/plugin_args'

  • Loading branch information...
commit 348a8f9b50112a9df1244d5c73ac27e5c435e359 2 parents 7bfa956 + b51ce95
@ambs ambs authored
Showing with 20 additions and 2 deletions.
  1. +18 −0 lib/Dancer/Plugin.pm
  2. +2 −2 t/lib/FooPlugin.pm
View
18 lib/Dancer/Plugin.pm
@@ -157,6 +157,23 @@ sub register_plugin {
$dsl->dancer_app->register_plugin($dsl);
}
+=method plugin_args
+
+Simple method to retrieve the parameters or arguments passed to a
+plugin-defined keyword. Although not relevant for Dancer 1 only, or
+Dancer 2 only, plugins, it is useful for universal plugins.
+
+ register foo => sub {
+ my ($self, @args) = plugin_args(@_);
+ ...
+ }
+
+Note that Dancer 1 will return undef as the object reference.
+
+=cut
+
+sub plugin_args { @_ }
+
=method plugin_setting
If C<plugin_setting> is called inside a plugin, the appropriate configuration
@@ -267,6 +284,7 @@ sub import {
register_plugin
register
plugin_setting
+ plugin_args
);
for my $symbol (@export) {
no strict 'refs';
View
4 t/lib/FooPlugin.pm
@@ -10,13 +10,13 @@ sub _html_sitemap {
}
register foo_wrap_request => sub {
- my ($self) = @_;
+ my ($self) = plugin_args(@_);
return $self->request;
},
{ is_global => 0 };
register foo_route => sub {
- my $self = shift;
+ my ($self) = plugin_args(@_);
$self->get('/foo', sub {'foo'});
};
Please sign in to comment.
Something went wrong with that request. Please try again.