Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Showing with 35 additions and 8 deletions.
  1. +30 −3 lib/Dancer/Core/App.pm
  2. +0 −1 lib/Dancer/Core/Role/DSL.pm
  3. +2 −4 lib/Dancer/Core/Role/Hookable.pm
  4. +2 −0 lib/Dancer/Plugin.pm
  5. +1 −0 lib/Dancer/Test.pm
View
33 lib/Dancer/Core/App.pm
@@ -23,6 +23,18 @@ sub supported_hooks {
/
}
+has plugins => (
+ is => 'rw',
+ isa => sub { ArrayRef(@_) },
+ default => sub { [] },
+);
+
+sub register_plugin {
+ my ($self, $plugin) = @_;
+ Dancer::core_debug("Registered $plugin");
+ push @{ $self->plugins }, $plugin;
+}
+
around BUILDARGS => sub {
my $orig = shift;
my ( $class, %args ) = @_;
@@ -157,11 +169,25 @@ sub hook_candidates {
}
# TODO : get the list of all plugins registered
- my @plugins;
+ my @plugins = @{ $self->plugins };
(@route_handlers, @engines, @plugins);
}
+sub all_hook_aliases {
+ my ($self) = @_;
+
+ my $aliases = $self->hook_aliases;
+ for my $plugin (@{ $self->plugins }) {
+ $aliases = {
+ %{$aliases},
+ %{ $plugin->hook_aliases },
+ };
+ }
+
+ return $aliases;
+}
+
has postponed_hooks => (
is => 'ro',
isa => sub { HashRef(@_) },
@@ -177,14 +203,15 @@ around add_hook => sub {
my ($package, $file, $line) = caller(4); # deep to 4 : user's app code
my $add_hook_caller = [ $package, $file, $line ];
+
my ($hook) = @_;
my $name = $hook->name;
- my $hook_aliases = $self->hook_aliases;
+
+ my $hook_aliases = $self->all_hook_aliases;
# backward compat with previous hook format
$name = $hook_aliases->{$name}
if defined $hook_aliases->{$name};
-
$hook->name($name);
# if that hook belongs to the app, register it now and return
View
1 lib/Dancer/Core/Role/DSL.pm
@@ -14,7 +14,6 @@ has keywords => (
builder => '_build_dsl_keywords',
);
-# needs to be overwritten by plugins who claim hooks
sub supported_hooks { }
sub _build_dsl_keywords {
View
6 lib/Dancer/Core/Role/Hookable.pm
@@ -43,8 +43,6 @@ after BUILD => sub {
sub _add_postponed_hooks {
my ( $self, $args ) = @_;
- #Dancer::core_debug("building $self with postponed hooks: ", $postponed_hooks);
-
my $postponed_hooks = $args->{postponed_hooks};
# find the internal name of the hooks, from the caller name
@@ -56,7 +54,7 @@ sub _add_postponed_hooks {
$h_type = 'engine';
}
- #Dancer::core_debug("looking for hooks for $h_type/$h_name");
+# Dancer::core_debug("looking for hooks for $h_type/$h_name");
# keep only the hooks we want
$postponed_hooks = $postponed_hooks->{$h_type}{$h_name};
return unless defined $postponed_hooks;
@@ -69,7 +67,7 @@ sub _add_postponed_hooks {
or croak "$h_name $h_type does not support the hook `$name'. ("
. join( ", ", @{$caller} ) .")";
- Dancer::core_debug("Adding hook '$name' to $self");
+# Dancer::core_debug("Adding hook '$name' to $self");
$self->add_hook($hook);
}
}
View
2 lib/Dancer/Plugin.pm
@@ -117,6 +117,8 @@ sub register_plugin {
Moo::Role->apply_roles_to_object($dsl, $plugin);
$dsl->export_symbols_to($caller);
+
+ $dsl->dancer_app->register_plugin($dsl);
}
sub plugin_setting {
View
1 lib/Dancer/Test.pm
@@ -19,6 +19,7 @@ our @EXPORT = qw(
response_headers_include
response_headers_are_deeply
response_content_like
+ response_content_unlike
response_content_is_deeply
response_is_file
);

No commit comments for this range

Something went wrong with that request. Please try again.