line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Declare::Syntax::KeywordHandling; |
2
|
|
|
|
|
|
|
# ABSTRACT: Basic keyword functionality |
3
|
|
|
|
|
|
|
$MooseX::Declare::Syntax::KeywordHandling::VERSION = '0.39'; |
4
|
24
|
|
|
24
|
|
24555
|
use Moose::Role; |
|
24
|
|
|
|
|
515
|
|
|
24
|
|
|
|
|
233
|
|
5
|
24
|
|
|
24
|
|
148354
|
use Moose::Util::TypeConstraints; |
|
24
|
|
|
|
|
67
|
|
|
24
|
|
|
|
|
264
|
|
6
|
24
|
|
|
24
|
|
63163
|
use Devel::Declare (); |
|
24
|
|
|
|
|
62
|
|
|
24
|
|
|
|
|
654
|
|
7
|
24
|
|
|
24
|
|
142
|
use Sub::Install qw( install_sub ); |
|
24
|
|
|
|
|
50
|
|
|
24
|
|
|
|
|
622
|
|
8
|
24
|
|
|
24
|
|
2528
|
use Moose::Meta::Class (); |
|
24
|
|
|
|
|
49
|
|
|
24
|
|
|
|
|
621
|
|
9
|
24
|
|
|
24
|
|
144
|
use List::MoreUtils qw( uniq ); |
|
24
|
|
|
|
|
51
|
|
|
24
|
|
|
|
|
1792
|
|
10
|
24
|
|
|
24
|
|
165
|
use Module::Runtime 'use_module'; |
|
24
|
|
|
|
|
49
|
|
|
24
|
|
|
|
|
238
|
|
11
|
|
|
|
|
|
|
|
12
|
24
|
|
|
24
|
|
1820
|
use aliased 'MooseX::Declare::Context'; |
|
24
|
|
|
|
|
56
|
|
|
24
|
|
|
|
|
221
|
|
13
|
|
|
|
|
|
|
|
14
|
24
|
|
|
24
|
|
3059
|
use namespace::clean -except => 'meta'; |
|
24
|
|
|
|
|
54
|
|
|
24
|
|
|
|
|
348
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
17
|
|
|
|
|
|
|
#pod |
18
|
|
|
|
|
|
|
#pod This role provides the functionality common for all keyword handlers |
19
|
|
|
|
|
|
|
#pod in L<MooseX::Declare>. |
20
|
|
|
|
|
|
|
#pod |
21
|
|
|
|
|
|
|
#pod =head1 REQUIRED METHODS |
22
|
|
|
|
|
|
|
#pod |
23
|
|
|
|
|
|
|
#pod =head2 parse |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod Object->parse (Object $context) |
26
|
|
|
|
|
|
|
#pod |
27
|
|
|
|
|
|
|
#pod This method must implement the actual parsing of the keyword syntax. |
28
|
|
|
|
|
|
|
#pod |
29
|
|
|
|
|
|
|
#pod =cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
requires qw( |
32
|
|
|
|
|
|
|
parse |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#pod =attr identifier |
36
|
|
|
|
|
|
|
#pod |
37
|
|
|
|
|
|
|
#pod This is the name of the actual keyword. It is a required string that is in |
38
|
|
|
|
|
|
|
#pod the same format as a usual Perl identifier. |
39
|
|
|
|
|
|
|
#pod |
40
|
|
|
|
|
|
|
#pod =cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has identifier => ( |
43
|
|
|
|
|
|
|
is => 'ro', |
44
|
|
|
|
|
|
|
isa => subtype(as 'Str', where { /^ [_a-z] [_a-z0-9]* $/ix }), |
45
|
|
|
|
|
|
|
required => 1, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#pod =method get_identifier |
49
|
|
|
|
|
|
|
#pod |
50
|
|
|
|
|
|
|
#pod Str Object->get_identifier () |
51
|
|
|
|
|
|
|
#pod |
52
|
|
|
|
|
|
|
#pod Returns the name the handler will be setup under. |
53
|
|
|
|
|
|
|
#pod |
54
|
|
|
|
|
|
|
#pod =cut |
55
|
|
|
|
|
|
|
|
56
|
879
|
|
|
879
|
1
|
54056
|
sub get_identifier { shift->identifier } |
57
|
|
|
|
|
|
|
|
58
|
129
|
|
|
129
|
0
|
461
|
sub context_class { Context } |
59
|
|
|
|
|
|
|
|
60
|
66
|
|
|
66
|
0
|
618
|
sub context_traits { } |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#pod =method setup_for |
63
|
|
|
|
|
|
|
#pod |
64
|
|
|
|
|
|
|
#pod Object->setup_for (ClassName $class, %args) |
65
|
|
|
|
|
|
|
#pod |
66
|
|
|
|
|
|
|
#pod This will setup the handler in the specified C<$class>. The handler will |
67
|
|
|
|
|
|
|
#pod dispatch to the L</parse_declaration> method when the keyword is used. |
68
|
|
|
|
|
|
|
#pod |
69
|
|
|
|
|
|
|
#pod A normal code reference will also be exported into the calling namespace. |
70
|
|
|
|
|
|
|
#pod It will either be empty or, if a C<generate_export> method is provided, |
71
|
|
|
|
|
|
|
#pod the return value of that method. |
72
|
|
|
|
|
|
|
#pod |
73
|
|
|
|
|
|
|
#pod =cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub setup_for { |
76
|
749
|
|
|
749
|
1
|
4312
|
my ($self, $setup_class, %args) = @_; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# make sure the stack is valid |
79
|
749
|
|
100
|
|
|
2521
|
my $stack = $args{stack} || []; |
80
|
749
|
|
|
|
|
2031
|
my $ident = $self->get_identifier; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# setup the D:D handler for our keyword |
83
|
|
|
|
|
|
|
Devel::Declare->setup_for($setup_class, { |
84
|
|
|
|
|
|
|
$ident => { |
85
|
129
|
|
|
129
|
|
3292754
|
const => sub { $self->parse_declaration((caller(1))[1], \%args, @_) }, |
86
|
|
|
|
|
|
|
}, |
87
|
749
|
|
|
|
|
8816
|
}); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# search or generate a real export |
90
|
749
|
100
|
|
5
|
|
22047
|
my $export = $self->can('generate_export') ? $self->generate_export($setup_class) : sub { }; |
|
5
|
|
|
|
|
41
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# export subroutine |
93
|
749
|
100
|
|
|
|
10333
|
install_sub({ |
94
|
|
|
|
|
|
|
code => $export, |
95
|
|
|
|
|
|
|
into => $setup_class, |
96
|
|
|
|
|
|
|
as => $ident, |
97
|
|
|
|
|
|
|
}) unless $setup_class->can($ident); |
98
|
|
|
|
|
|
|
|
99
|
749
|
|
|
|
|
67649
|
return 1; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#pod =method parse_declaration |
103
|
|
|
|
|
|
|
#pod |
104
|
|
|
|
|
|
|
#pod Object->parse_declaration (Str $filename, HashRef $setup_args, @call_args) |
105
|
|
|
|
|
|
|
#pod |
106
|
|
|
|
|
|
|
#pod This simply creates a new L<context|MooseX::Declare::Context> and passes it |
107
|
|
|
|
|
|
|
#pod to the L</parse> method. |
108
|
|
|
|
|
|
|
#pod |
109
|
|
|
|
|
|
|
#pod =cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub parse_declaration { |
112
|
129
|
|
|
129
|
1
|
569
|
my ($self, $caller_file, $args, @ctx_args) = @_; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# find and load context object class |
115
|
129
|
|
|
|
|
649
|
my $ctx_class = $self->context_class; |
116
|
129
|
|
|
|
|
833
|
use_module $ctx_class; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# do we have traits? |
119
|
129
|
100
|
|
|
|
5459
|
if (my @ctx_traits = uniq $self->context_traits) { |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
use_module $_ |
122
|
73
|
|
|
|
|
1538
|
for @ctx_traits; |
123
|
|
|
|
|
|
|
|
124
|
73
|
|
|
|
|
4166
|
$ctx_class = Moose::Meta::Class->create_anon_class( |
125
|
|
|
|
|
|
|
superclasses => [$ctx_class], |
126
|
|
|
|
|
|
|
roles => [@ctx_traits], |
127
|
|
|
|
|
|
|
cache => 1, |
128
|
|
|
|
|
|
|
)->name; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# create a context object and initialize it |
132
|
129
|
|
|
|
|
2066
|
my $ctx = $ctx_class->new( |
133
|
129
|
|
|
|
|
67331
|
%{ $args }, |
134
|
|
|
|
|
|
|
caller_file => $caller_file, |
135
|
|
|
|
|
|
|
); |
136
|
129
|
|
|
|
|
2084
|
$ctx->init(@ctx_args); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# parse with current context |
139
|
129
|
|
|
|
|
5116
|
return $self->parse($ctx); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
143
|
|
|
|
|
|
|
#pod |
144
|
|
|
|
|
|
|
#pod =for :list |
145
|
|
|
|
|
|
|
#pod * L<MooseX::Declare> |
146
|
|
|
|
|
|
|
#pod * L<MooseX::Declare::Context> |
147
|
|
|
|
|
|
|
#pod |
148
|
|
|
|
|
|
|
#pod =cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__END__ |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=pod |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=encoding UTF-8 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 NAME |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
MooseX::Declare::Syntax::KeywordHandling - Basic keyword functionality |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 VERSION |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
version 0.39 |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 DESCRIPTION |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This role provides the functionality common for all keyword handlers |
169
|
|
|
|
|
|
|
in L<MooseX::Declare>. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 identifier |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is the name of the actual keyword. It is a required string that is in |
176
|
|
|
|
|
|
|
the same format as a usual Perl identifier. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 METHODS |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 get_identifier |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Str Object->get_identifier () |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Returns the name the handler will be setup under. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 setup_for |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Object->setup_for (ClassName $class, %args) |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This will setup the handler in the specified C<$class>. The handler will |
191
|
|
|
|
|
|
|
dispatch to the L</parse_declaration> method when the keyword is used. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
A normal code reference will also be exported into the calling namespace. |
194
|
|
|
|
|
|
|
It will either be empty or, if a C<generate_export> method is provided, |
195
|
|
|
|
|
|
|
the return value of that method. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 parse_declaration |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Object->parse_declaration (Str $filename, HashRef $setup_args, @call_args) |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This simply creates a new L<context|MooseX::Declare::Context> and passes it |
202
|
|
|
|
|
|
|
to the L</parse> method. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 REQUIRED METHODS |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 parse |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Object->parse (Object $context) |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
This method must implement the actual parsing of the keyword syntax. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 SEE ALSO |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=over 4 |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item * |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
L<MooseX::Declare> |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item * |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
L<MooseX::Declare::Context> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 AUTHOR |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
This software is copyright (c) 2008 by Florian Ragwitz. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
235
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |