Dancer2
view release on metacpan or search on metacpan
lib/Dancer2/Plugin.pm view on Meta::CPAN
package Dancer2::Plugin;
# ABSTRACT: base class for Dancer2 plugins
$Dancer2::Plugin::VERSION = '2.1.0';
use strict;
use warnings;
use Moo;
use Carp;
use List::Util qw/ reduce /;
use Module::Runtime 'require_module';
use Attribute::Handlers;
use Scalar::Util;
use Ref::Util qw<is_arrayref is_coderef>;
our $CUR_PLUGIN;
extends 'Exporter::Tiny';
with 'Dancer2::Core::Role::Hookable';
has app => (
is => 'ro',
weak_ref => 1,
required => 1,
);
has config => (
is => 'ro',
lazy => 1,
default => sub {
my $self = shift;
my $config = $self->app->config;
my $package = ref $self; # TODO
$package =~ s/Dancer2::Plugin:://;
$config->{plugins}{$package} || {};
},
);
my $_keywords = {};
sub keywords { $_keywords }
my $REF_ADDR_REGEX = qr{
[A-Za-z0-9\:\_]+
=HASH
\(
([0-9a-fx]+)
\)
}x;
my %instances;
# backwards compatibility
our $_keywords_by_plugin = {};
has '+hooks' => (
default => sub {
my $plugin = shift;
my $name = 'plugin.' . lc ref $plugin;
$name =~ s/Dancer2::Plugin:://i;
$name =~ s/::/_/g;
+{
map { join( '.', $name, $_ ) => [] }
@{ $plugin->ClassHooks }
};
},
);
sub add_hooks {
my $class = shift;
push @{ $class->ClassHooks }, @_;
}
sub execute_plugin_hook {
( run in 0.811 second using v1.01-cache-2.11-cpan-39bf76dae61 )