line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Meta::Signature::Combined; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
7919
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use MooseX::Meta::Signature::Named; |
6
|
|
|
|
|
|
|
use MooseX::Meta::Signature::Positional; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has named_signature => (is => 'ro',isa => 'MooseX::Meta::Signature::Named'); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has positional_signature => (is => 'ro',isa => 'MooseX::Meta::Signature::Positional'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has positional_signature_size => (is => 'ro',isa => 'Int'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with qw/MooseX::Meta::Signature/; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:BERLE'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _positional_metaclass { 'MooseX::Meta::Signature::Positional' } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _named_metaclass { 'MooseX::Meta::Signature::Named' } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
|
|
|
|
|
|
my ($class,@parameters) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $self = $class->meta->new_object; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my @positional_params; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %named_params; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
while (my $param = shift @parameters) { |
34
|
|
|
|
|
|
|
if (ref $param) { |
35
|
|
|
|
|
|
|
$param->{required} = 1 |
36
|
|
|
|
|
|
|
if ref $param eq 'HASH'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
push @positional_params,$param; |
39
|
|
|
|
|
|
|
} else { |
40
|
|
|
|
|
|
|
$named_params{$param} = shift @parameters; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self->{named_signature} = $self->_named_metaclass->new (%named_params); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->{positional_signature} = $self->_positional_metaclass->new (@positional_params); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->{positional_signature_size} = scalar @positional_params; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub validate { |
54
|
|
|
|
|
|
|
my ($self,@args) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my @positional_args = (scalar @args <= $self->{positional_signature_size} ? @args : @args[0..($self->{positional_signature_size} - 1)]); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my %named_args = @args[$self->{positional_signature_size}..$#args]; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return |
61
|
|
|
|
|
|
|
$self->{positional_signature}->validate (@positional_args), |
62
|
|
|
|
|
|
|
$self->{named_signature}->validate (%named_args); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(inline_constructor => 0); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
MooseX::Meta::Signature::Combined - Combined signature metaclass |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 WARNING |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This API is unstable, it may change at any time. This should not |
80
|
|
|
|
|
|
|
affect ordinary L<MooseX::Method> usage. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SYNOPSIS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use MooseX::Meta::Signature::Combined; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $signature = MooseX::Meta::Signature::Combined->new ( |
87
|
|
|
|
|
|
|
{ isa => 'Int' }, |
88
|
|
|
|
|
|
|
foo => { required => 1 }, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my @results; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
eval { |
94
|
|
|
|
|
|
|
@results = $signature->validate (23,bar => 2); |
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 METHODS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item B<validate> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Validates the arguments against the signature. The first arguments |
104
|
|
|
|
|
|
|
must be the positional ones. The named arguments must be in the |
105
|
|
|
|
|
|
|
form of a hash, unlike the named signature this does not support |
106
|
|
|
|
|
|
|
hashrefs. Returns a list of the validated positional arguments |
107
|
|
|
|
|
|
|
and a hashref of the validated named arguments or throws an |
108
|
|
|
|
|
|
|
exception on validation error. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item B<named_signature> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Returns the named signature. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item B<positional_signature> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns the positional signature. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item B<positional_signature_size> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Returns the length of the positional signature. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=back |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 BUGS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Most software has bugs. This module probably isn't an exception. |
127
|
|
|
|
|
|
|
If you find a bug please either email me, or add the bug to cpan-RT. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Anders Nor Berle E<lt>debolaz@gmail.comE<gt> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright 2007 by Anders Nor Berle. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
138
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|