Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeConstraint/DuckType.pm |
Statements | Executed 23 statements in 534µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 15µs | 47µs | BEGIN@10 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 9µs | 10µs | BEGIN@4 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 5µs | 15µs | BEGIN@8 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 5µs | 88µs | BEGIN@11 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 5µs | 24µs | BEGIN@9 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 4µs | 8µs | BEGIN@5 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 4µs | 248µs | BEGIN@6 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 4µs | 17µs | BEGIN@15 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 3µs | 3µs | BEGIN@13 | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | __ANON__[:34] | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | __ANON__[:45] | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | __ANON__[:46] | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | create_child_type | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | equals | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | get_message | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | new | Moose::Meta::TypeConstraint::DuckType::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::TypeConstraint::DuckType; | ||||
2 | 1 | 300ns | our $VERSION = '2.1605'; | ||
3 | |||||
4 | 2 | 15µs | 2 | 12µs | # spent 10µs (9+1) within Moose::Meta::TypeConstraint::DuckType::BEGIN@4 which was called:
# once (9µs+1µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 4 # spent 10µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@4
# spent 1µs making 1 call to strict::import |
5 | 2 | 18µs | 2 | 12µs | # spent 8µs (4+3) within Moose::Meta::TypeConstraint::DuckType::BEGIN@5 which was called:
# once (4µs+3µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 5 # spent 8µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@5
# spent 4µs making 1 call to warnings::import |
6 | 2 | 20µs | 2 | 491µs | # spent 248µs (4+244) within Moose::Meta::TypeConstraint::DuckType::BEGIN@6 which was called:
# once (4µs+244µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 6 # spent 248µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@6
# spent 244µs making 1 call to metaclass::import |
7 | |||||
8 | 2 | 16µs | 2 | 25µs | # spent 15µs (5+10) within Moose::Meta::TypeConstraint::DuckType::BEGIN@8 which was called:
# once (5µs+10µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 8 # spent 15µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@8
# spent 10µs making 1 call to Exporter::import |
9 | 2 | 21µs | 2 | 43µs | # spent 24µs (5+19) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called:
# once (5µs+19µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 9 # spent 24µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9
# spent 19µs making 1 call to Exporter::import |
10 | 3 | 91µs | 3 | 66µs | # spent 47µs (15+32) within Moose::Meta::TypeConstraint::DuckType::BEGIN@10 which was called:
# once (15µs+32µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 10 # spent 47µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@10
# spent 11µs making 1 call to UNIVERSAL::VERSION
# spent 7µs making 1 call to List::Util::import |
11 | 2 | 19µs | 2 | 171µs | # spent 88µs (5+83) within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called:
# once (5µs+83µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 11 # spent 88µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11
# spent 83µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
12 | |||||
13 | 2 | 13µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@13 which was called:
# once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@31 at line 13 # spent 3µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@13 |
14 | |||||
15 | 2 | 313µs | 2 | 30µs | # spent 17µs (4+13) within Moose::Meta::TypeConstraint::DuckType::BEGIN@15 which was called:
# once (4µs+13µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 15 # spent 17µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@15
# spent 13µs making 1 call to parent::import |
16 | |||||
17 | 1 | 3µs | 3 | 214µs | __PACKAGE__->meta->add_attribute('methods' => ( # spent 199µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::DuckType::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
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 | 1 | 1µs | }; | ||
35 | |||||
36 | sub new { | ||||
37 | my ( $class, %args ) = @_; | ||||
38 | |||||
39 | $args{parent} | ||||
40 | = Moose::Util::TypeConstraints::find_type_constraint('Object'); | ||||
41 | |||||
42 | my @methods = @{ $args{methods} }; | ||||
43 | $args{constraint} = sub { | ||||
44 | my $val = $_[0]; | ||||
45 | return all { $val->can($_) } @methods; | ||||
46 | }; | ||||
47 | |||||
48 | $args{inlined} = $inliner; | ||||
49 | |||||
50 | my $self = $class->SUPER::new(\%args); | ||||
51 | |||||
52 | $self->compile_type_constraint() | ||||
53 | unless $self->_has_compiled_type_constraint; | ||||
54 | |||||
55 | return $self; | ||||
56 | } | ||||
57 | |||||
58 | sub equals { | ||||
59 | my ( $self, $type_or_name ) = @_; | ||||
60 | |||||
61 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
62 | |||||
63 | return unless $other->isa(__PACKAGE__); | ||||
64 | |||||
65 | my @self_methods = sort @{ $self->methods }; | ||||
66 | my @other_methods = sort @{ $other->methods }; | ||||
67 | |||||
68 | return unless @self_methods == @other_methods; | ||||
69 | |||||
70 | while ( @self_methods ) { | ||||
71 | my $method = shift @self_methods; | ||||
72 | my $other_method = shift @other_methods; | ||||
73 | |||||
74 | return unless $method eq $other_method; | ||||
75 | } | ||||
76 | |||||
77 | return 1; | ||||
78 | } | ||||
79 | |||||
80 | sub create_child_type { | ||||
81 | my ($self, @args) = @_; | ||||
82 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
83 | } | ||||
84 | |||||
85 | sub get_message { | ||||
86 | my $self = shift; | ||||
87 | my ($value) = @_; | ||||
88 | |||||
89 | if ($self->has_message) { | ||||
90 | return $self->SUPER::get_message(@_); | ||||
91 | } | ||||
92 | |||||
93 | return $self->SUPER::get_message($value) unless blessed($value); | ||||
94 | |||||
95 | my @methods = grep { !$value->can($_) } @{ $self->methods }; | ||||
96 | my $class = blessed $value; | ||||
97 | $class ||= $value; | ||||
98 | |||||
99 | return $class | ||||
100 | . " is missing methods " | ||||
101 | . english_list(map { "'$_'" } @methods); | ||||
102 | } | ||||
103 | |||||
104 | 1 | 4µs | 1; | ||
105 | |||||
106 | # ABSTRACT: Type constraint for duck typing | ||||
107 | |||||
108 | __END__ |