line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Meta::Signature::Positional::Compiled; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
4584
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use HTML::Template::Pro; |
6
|
|
|
|
|
|
|
use MooseX::Meta::Parameter::Moose::Compiled; |
7
|
|
|
|
|
|
|
use MooseX::Method::Constant; |
8
|
|
|
|
|
|
|
use MooseX::Method::Exception; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends qw/MooseX::Meta::Signature::Positional/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with qw/MooseX::Meta::Signature::Compiled/; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:BERLE'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $compile_template = HTML::Template::Pro->new (scalarref => \<< 'EOF'); |
19
|
|
|
|
|
|
|
sub { |
20
|
|
|
|
|
|
|
my @values = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
<TMPL_VAR NAME="body"> |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return @values; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
EOF |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $as_perl_template = HTML::Template::Pro->new (scalarref => \<< 'EOF'); |
29
|
|
|
|
|
|
|
my $pos = 0; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
eval { |
32
|
|
|
|
|
|
|
my $provided; |
33
|
|
|
|
|
|
|
<TMPL_LOOP NAME="parameters"> |
34
|
|
|
|
|
|
|
<TMPL_IF NAME="has_inline"> |
35
|
|
|
|
|
|
|
$provided = $#values >= <TMPL_VAR NAME="pos">; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$_ = $values[<TMPL_VAR NAME="pos">]; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
<TMPL_VAR NAME="body"> |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$values[<TMPL_VAR NAME="pos">] = $_; |
42
|
|
|
|
|
|
|
<TMPL_ELSE> |
43
|
|
|
|
|
|
|
$values[<TMPL_VAR NAME="pos">] = <TMPL_VAR NAME="parameter">->validate ($values[<TMPL_VAR NAME="pos">]); |
44
|
|
|
|
|
|
|
</TMPL_IF> |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$pos++; |
47
|
|
|
|
|
|
|
</TMPL_LOOP> |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if ($@) { |
51
|
|
|
|
|
|
|
if (Scalar::Util::blessed $@ && $@->isa ('MooseX::Method::Exception')) { |
52
|
|
|
|
|
|
|
$@->error ("Parameter $pos: " . $@->error); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$@->rethrow; |
55
|
|
|
|
|
|
|
} else { |
56
|
|
|
|
|
|
|
die $@; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
EOF |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _parameter_metaclass { 'MooseX::Meta::Parameter::Moose::Compiled' } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
override new => sub { |
64
|
|
|
|
|
|
|
my $self = super; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->{params} = $self->_setup_params; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $self; |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub validate { |
72
|
|
|
|
|
|
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->{compiled_validator} ||= $self->compile; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return $self->{compiled_validator}->(@_); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub compile { |
80
|
|
|
|
|
|
|
my ($self) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$compile_template->param (body => $self->as_perl); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $coderef = eval $compile_template->output; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
MooseX::Method::Exception->throw ("Compilation failed: $@") |
87
|
|
|
|
|
|
|
if ($@); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return $coderef; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub as_perl { |
93
|
|
|
|
|
|
|
my ($self) = @_; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$as_perl_template->param ($self->{params}); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return $as_perl_template->output; |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _setup_params { |
101
|
|
|
|
|
|
|
my ($self) = @_; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $params = { |
104
|
|
|
|
|
|
|
parameters => [], |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $pos = 0; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
for (@{ $self->{'@!parameter_map'} }) { |
110
|
|
|
|
|
|
|
my $parameter_params = { |
111
|
|
|
|
|
|
|
pos => $pos, |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if ($_->does ('MooseX::Meta::Parameter::Compiled')) { |
115
|
|
|
|
|
|
|
$parameter_params->{'has_inline'} = 1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$parameter_params->{'body'} = $_->as_perl; |
118
|
|
|
|
|
|
|
} else { |
119
|
|
|
|
|
|
|
$parameter_params->{'parameter'} = MooseX::Method::Constant->make ($_); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
push @{ $params->{parameters} },$parameter_params; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$pos++; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
return $params; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(inline_constructor => 0); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=pod |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 NAME |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
MooseX::Meta::Signature::Positional::Compiled - Compiled positional signature |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 WARNING |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This API is unstable, it may change at any time. This should not |
145
|
|
|
|
|
|
|
affect ordinary L<MooseX::Method> usage. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 SYNOPSIS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
use MooseX::Meta::Signature::Positional::Compiled; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my $validator = MooseX::Meta::Signature::Positional::Compiled->new ({ isa => 'Int' })->compile; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
eval { |
154
|
|
|
|
|
|
|
$validator->(42); |
155
|
|
|
|
|
|
|
}; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 METHODS |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=over 4 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item validate |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Overriden from the superclass. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item compile |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Produces a validator coderef. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item as_perl |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Spits out most of the perl code used to produce the coderef above. |
172
|
|
|
|
|
|
|
This is primarily used internally for inlining. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 BUGS |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Most software has bugs. This module probably isn't an exception. |
179
|
|
|
|
|
|
|
If you find a bug please either email me, or add the bug to cpan-RT. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Anders Nor Berle E<lt>debolaz@gmail.comE<gt> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Copyright 2007 by Anders Nor Berle. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
190
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|