| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooseX::Meta::Signature::Named; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
8818
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Moose::Util qw/does_role/; |
|
6
|
|
|
|
|
|
|
use MooseX::Meta::Parameter::Moose; |
|
7
|
|
|
|
|
|
|
use MooseX::Method::Exception; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with qw/MooseX::Meta::Signature/; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:BERLE'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _parameter_metaclass { 'MooseX::Meta::Parameter::Moose' } |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
|
|
|
|
|
|
my ($class,%parameters) = @_; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $self = $class->meta->new_object; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$self->{'%!parameter_map'} = {}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
for (keys %parameters) { |
|
25
|
|
|
|
|
|
|
my $parameter = $parameters{$_}; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if (ref $parameter eq 'HASH') { |
|
28
|
|
|
|
|
|
|
if (exists $parameter->{metaclass}) { |
|
29
|
|
|
|
|
|
|
$parameter = $parameter->{metaclass}->new ($parameter); |
|
30
|
|
|
|
|
|
|
} else { |
|
31
|
|
|
|
|
|
|
$parameter = $self->_parameter_metaclass->new ($parameter); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
MooseX::Method::Exception->throw ("Parameter must be a MooseX::Meta::Parameter or coercible into one") |
|
36
|
|
|
|
|
|
|
unless does_role ($parameter,'MooseX::Meta::Parameter'); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$self->{'%!parameter_map'}->{$_} = $parameter; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return $self; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub validate { |
|
45
|
|
|
|
|
|
|
my $self = shift; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $args; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
if (ref $_[0] eq 'HASH') { |
|
50
|
|
|
|
|
|
|
$args = $_[0]; |
|
51
|
|
|
|
|
|
|
} else { |
|
52
|
|
|
|
|
|
|
$args = { @_ }; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $name; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
eval { |
|
58
|
|
|
|
|
|
|
for (keys %{$self->{'%!parameter_map'}}) { |
|
59
|
|
|
|
|
|
|
$name = $_; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$args->{$_} = $self->{'%!parameter_map'}->{$_}->validate (( exists $args->{$_} ? $args->{$_} : ())); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
}; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
if ($@) { |
|
66
|
|
|
|
|
|
|
if (blessed $@ && $@->isa ('MooseX::Method::Exception')) { |
|
67
|
|
|
|
|
|
|
$@->error ("Parameter ($name): " . $@->error); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$@->rethrow; |
|
70
|
|
|
|
|
|
|
} else { |
|
71
|
|
|
|
|
|
|
die $@; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $args; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub export { |
|
79
|
|
|
|
|
|
|
my ($self) = @_; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $export = {}; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$export->{$_} = $self->{'%!parameter_map'}->{$_}->export |
|
84
|
|
|
|
|
|
|
for keys %{$self->{'%!parameter_map'}}; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $export; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(inline_constructor => 0); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=pod |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
MooseX::Meta::Signature::Named - Named signature metaclass |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 WARNING |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This API is unstable, it may change at any time. This should not |
|
104
|
|
|
|
|
|
|
affect ordinary L<MooseX::Method> usage. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
use MooseX::Meta::Signature::Named; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $signature = MooseX::Meta::Signature::Named->new ( |
|
111
|
|
|
|
|
|
|
foo => { required => 1 }, |
|
112
|
|
|
|
|
|
|
bar => { required => 1 }, |
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $results; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
eval { |
|
118
|
|
|
|
|
|
|
$results = $signature->validate (foo => 1); |
|
119
|
|
|
|
|
|
|
}; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
print Dumper($signature->export); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 METHODS |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=over 4 |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item B<validate> |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Validate the arguments against the signature. Accepts arguments in the |
|
130
|
|
|
|
|
|
|
form of a hashref or a hash. Returns a hashref of the validated |
|
131
|
|
|
|
|
|
|
arguments or throws an exception on validation error. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item B<export> |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Exports a data structure representing the signature. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 BUGS |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Most software has bugs. This module probably isn't an exception. |
|
142
|
|
|
|
|
|
|
If you find a bug please either email me, or add the bug to cpan-RT. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Anders Nor Berle E<lt>debolaz@gmail.comE<gt> |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Copyright 2007 by Anders Nor Berle. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
153
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
|
156
|
|
|
|
|
|
|
|