line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::TypeConstraint::DuckType; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2203'; |
3
|
|
|
|
|
|
|
|
4
|
401
|
|
|
401
|
|
2807
|
use strict; |
|
401
|
|
|
|
|
868
|
|
|
401
|
|
|
|
|
11439
|
|
5
|
401
|
|
|
401
|
|
1915
|
use warnings; |
|
401
|
|
|
|
|
774
|
|
|
401
|
|
|
|
|
8639
|
|
6
|
401
|
|
|
401
|
|
1907
|
use metaclass; |
|
401
|
|
|
|
|
776
|
|
|
401
|
|
|
|
|
2093
|
|
7
|
|
|
|
|
|
|
|
8
|
401
|
|
|
401
|
|
2754
|
use B; |
|
401
|
|
|
|
|
943
|
|
|
401
|
|
|
|
|
17487
|
|
9
|
401
|
|
|
401
|
|
2628
|
use Scalar::Util 'blessed'; |
|
401
|
|
|
|
|
1045
|
|
|
401
|
|
|
|
|
27250
|
|
10
|
401
|
|
|
401
|
|
2678
|
use List::Util 1.33 qw(all); |
|
401
|
|
|
|
|
7796
|
|
|
401
|
|
|
|
|
24534
|
|
11
|
401
|
|
|
401
|
|
2886
|
use Moose::Util 'english_list'; |
|
401
|
|
|
|
|
918
|
|
|
401
|
|
|
|
|
2729
|
|
12
|
|
|
|
|
|
|
|
13
|
401
|
|
|
401
|
|
89989
|
use Moose::Util::TypeConstraints (); |
|
401
|
|
|
|
|
893
|
|
|
401
|
|
|
|
|
8994
|
|
14
|
|
|
|
|
|
|
|
15
|
401
|
|
|
401
|
|
2080
|
use parent 'Moose::Meta::TypeConstraint'; |
|
401
|
|
|
|
|
852
|
|
|
401
|
|
|
|
|
2248
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('methods' => ( |
18
|
|
|
|
|
|
|
accessor => 'methods', |
19
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
20
|
|
|
|
|
|
|
)); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $inliner = sub { |
23
|
|
|
|
|
|
|
my $self = shift; |
24
|
|
|
|
|
|
|
my $val = shift; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return $self->parent->_inline_check($val) |
27
|
|
|
|
|
|
|
. ' && do {' . "\n" |
28
|
|
|
|
|
|
|
. 'my $val = ' . $val . ';' . "\n" |
29
|
|
|
|
|
|
|
. '&List::Util::all(' . "\n" |
30
|
|
|
|
|
|
|
. 'sub { $val->can($_) },' . "\n" |
31
|
|
|
|
|
|
|
. join(', ', map { B::perlstring($_) } @{ $self->methods }) |
32
|
|
|
|
|
|
|
. ');' . "\n" |
33
|
|
|
|
|
|
|
. '}'; |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
25
|
|
|
25
|
1
|
114
|
my ( $class, %args ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$args{parent} |
40
|
25
|
|
|
|
|
96
|
= Moose::Util::TypeConstraints::find_type_constraint('Object'); |
41
|
|
|
|
|
|
|
|
42
|
25
|
|
|
|
|
63
|
my @methods = @{ $args{methods} }; |
|
25
|
|
|
|
|
94
|
|
43
|
|
|
|
|
|
|
$args{constraint} = sub { |
44
|
8
|
|
|
8
|
|
16
|
my $val = $_[0]; |
45
|
8
|
|
|
|
|
44
|
return all { $val->can($_) } @methods; |
|
10
|
|
|
|
|
75
|
|
46
|
25
|
|
|
|
|
141
|
}; |
47
|
|
|
|
|
|
|
|
48
|
25
|
|
|
|
|
74
|
$args{inlined} = $inliner; |
49
|
|
|
|
|
|
|
|
50
|
25
|
|
|
|
|
209
|
my $self = $class->SUPER::new(\%args); |
51
|
|
|
|
|
|
|
|
52
|
25
|
50
|
|
|
|
818
|
$self->compile_type_constraint() |
53
|
|
|
|
|
|
|
unless $self->_has_compiled_type_constraint; |
54
|
|
|
|
|
|
|
|
55
|
25
|
|
|
|
|
152
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub equals { |
59
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $type_or_name ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
0
|
return unless $other->isa(__PACKAGE__); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
my @self_methods = sort @{ $self->methods }; |
|
0
|
|
|
|
|
0
|
|
66
|
0
|
|
|
|
|
0
|
my @other_methods = sort @{ $other->methods }; |
|
0
|
|
|
|
|
0
|
|
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
0
|
return unless @self_methods == @other_methods; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
while ( @self_methods ) { |
71
|
0
|
|
|
|
|
0
|
my $method = shift @self_methods; |
72
|
0
|
|
|
|
|
0
|
my $other_method = shift @other_methods; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
0
|
return unless $method eq $other_method; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
return 1; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub create_child_type { |
81
|
0
|
|
|
0
|
1
|
0
|
my ($self, @args) = @_; |
82
|
0
|
|
|
|
|
0
|
return Moose::Meta::TypeConstraint->new(@args, parent => $self); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub get_message { |
86
|
31
|
|
|
31
|
1
|
47
|
my $self = shift; |
87
|
31
|
|
|
|
|
54
|
my ($value) = @_; |
88
|
|
|
|
|
|
|
|
89
|
31
|
50
|
|
|
|
792
|
if ($self->has_message) { |
90
|
0
|
|
|
|
|
0
|
return $self->SUPER::get_message(@_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
31
|
100
|
|
|
|
136
|
return $self->SUPER::get_message($value) unless blessed($value); |
94
|
|
|
|
|
|
|
|
95
|
7
|
|
|
|
|
15
|
my @methods = grep { !$value->can($_) } @{ $self->methods }; |
|
13
|
|
|
|
|
57
|
|
|
7
|
|
|
|
|
170
|
|
96
|
7
|
|
|
|
|
19
|
my $class = blessed $value; |
97
|
7
|
|
33
|
|
|
18
|
$class ||= $value; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return $class |
100
|
|
|
|
|
|
|
. " is missing methods " |
101
|
7
|
|
|
|
|
18
|
. english_list(map { "'$_'" } @methods); |
|
12
|
|
|
|
|
38
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# ABSTRACT: Type constraint for duck typing |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=pod |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=encoding UTF-8 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Moose::Meta::TypeConstraint::DuckType - Type constraint for duck typing |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 VERSION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
version 2.2203 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 DESCRIPTION |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This class represents type constraints based on an enumerated list of |
125
|
|
|
|
|
|
|
required methods. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 INHERITANCE |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
C<Moose::Meta::TypeConstraint::DuckType> is a subclass of |
130
|
|
|
|
|
|
|
L<Moose::Meta::TypeConstraint>. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 METHODS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 Moose::Meta::TypeConstraint::DuckType->new(%options) |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This creates a new duck type constraint based on the given |
137
|
|
|
|
|
|
|
C<%options>. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
It takes the same options as its parent, with several |
140
|
|
|
|
|
|
|
exceptions. First, it requires an additional option, C<methods>. This |
141
|
|
|
|
|
|
|
should be an array reference containing a list of required method |
142
|
|
|
|
|
|
|
names. Second, it automatically sets the parent to the C<Object> type. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Finally, it ignores any provided C<constraint> option. The constraint |
145
|
|
|
|
|
|
|
is generated automatically based on the provided C<methods>. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 $constraint->methods |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Returns the array reference of required methods provided to the |
150
|
|
|
|
|
|
|
constructor. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 $constraint->create_child_type |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This returns a new L<Moose::Meta::TypeConstraint> object with the type |
155
|
|
|
|
|
|
|
as its parent. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Note that it does I<not> return a C<Moose::Meta::TypeConstraint::DuckType> |
158
|
|
|
|
|
|
|
object! |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 BUGS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
See L<Moose/BUGS> for details on reporting bugs. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AUTHORS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over 4 |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item * |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=back |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
215
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |