line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Pluggable; |
2
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
116277
|
use Catmandu::Sane; |
|
21
|
|
|
|
|
60
|
|
|
21
|
|
|
|
|
141
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
21
|
|
|
21
|
|
164
|
use Moo::Role; |
|
21
|
|
|
|
|
53
|
|
|
21
|
|
|
|
|
261
|
|
8
|
21
|
|
|
21
|
|
8091
|
use namespace::clean; |
|
21
|
|
|
|
|
48
|
|
|
21
|
|
|
|
|
128
|
|
9
|
|
|
|
|
|
|
|
10
|
16
|
|
|
16
|
1
|
2286
|
sub plugin_namespace {'Catmandu::Plugin'} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub with_plugins { |
13
|
15
|
|
|
15
|
1
|
33
|
my $class = shift; |
14
|
15
|
|
66
|
|
|
60
|
$class = ref $class || $class; |
15
|
15
|
50
|
|
|
|
71
|
my @plugins = ref $_[0] eq 'ARRAY' ? @{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
16
|
15
|
|
|
|
|
102
|
@plugins = split /,/, join ',', @plugins; |
17
|
15
|
50
|
|
|
|
45
|
@plugins || return $class; |
18
|
15
|
|
|
|
|
64
|
my $ns = $class->plugin_namespace; |
19
|
|
|
|
|
|
|
Moo::Role->create_class_with_roles( |
20
|
|
|
|
|
|
|
$class, |
21
|
|
|
|
|
|
|
map { |
22
|
15
|
|
|
|
|
42
|
my $pkg = $_; |
|
16
|
|
|
|
|
32
|
|
23
|
16
|
50
|
33
|
|
|
194
|
if ($pkg !~ s/^\+// && $pkg !~ /^$ns/) { |
24
|
16
|
|
|
|
|
58
|
$pkg = "${ns}::${pkg}"; |
25
|
|
|
|
|
|
|
} |
26
|
16
|
|
|
|
|
109
|
$pkg; |
27
|
|
|
|
|
|
|
} @plugins |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=pod |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Catmandu::Pluggable - A role for classes that need plugin capabilities |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package My::Foo::Bar; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Role::Tiny; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
before foo => sub { |
48
|
|
|
|
|
|
|
print "Before foo!\n"; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
after foo => sub { |
52
|
|
|
|
|
|
|
print "After foo!\n"; |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub extra { |
56
|
|
|
|
|
|
|
print "I can do extra too\n"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
package My::Foo; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Moo; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
with 'Catmandu::Pluggable'; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub plugin_namespace { |
66
|
|
|
|
|
|
|
'My::Foo'; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub foo { |
70
|
|
|
|
|
|
|
print "Foo!\n"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
package main; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $x = My::Foo->with_plugins('Bar')->new; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# prints: |
78
|
|
|
|
|
|
|
# Before foo! |
79
|
|
|
|
|
|
|
# Foo! |
80
|
|
|
|
|
|
|
# After foo! |
81
|
|
|
|
|
|
|
$x->foo; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# prints: |
84
|
|
|
|
|
|
|
# I can do extra too |
85
|
|
|
|
|
|
|
$x->extra; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 plugin_namespace |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns the namespace where all plugins for your class can be found. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 with_plugins(NAME) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 with_plugins(NAME,NAME,...) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This class method returns a subclass of your class with all provided plugins NAME-s implemented. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SEE ALSO |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L<Catmandu::Bag>, |
102
|
|
|
|
|
|
|
L<Catmandu::Plugin::Datestamps>, |
103
|
|
|
|
|
|
|
L<Catmandu::Plugin::Versioning> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |