Filename | /usr/local/lib/perl/5.14.2/Moose/Meta/TypeConstraint/DuckType.pm |
Statements | Executed 24 statements in 745µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 9µs | 9µs | BEGIN@2 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 8µs | 33µs | BEGIN@14 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 8µs | 18µs | BEGIN@10 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 8µs | 23µs | BEGIN@13 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 8µs | 11µs | BEGIN@9 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 7µs | 410µs | BEGIN@11 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 7µs | 28µs | BEGIN@15 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 7µs | 46µs | BEGIN@20 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 6µs | 158µs | BEGIN@16 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 5µs | 5µs | BEGIN@18 | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | __ANON__[:39] | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | __ANON__[:50] | Moose::Meta::TypeConstraint::DuckType::
0 | 0 | 0 | 0s | 0s | __ANON__[:51] | 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 | # spent 9µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@2 which was called:
# once (9µs+0s) by Moose::Util::TypeConstraints::BEGIN@39 at line 4 | ||||
3 | 1 | 6µs | $Moose::Meta::TypeConstraint::DuckType::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 31µs | 1 | 9µs | } # spent 9µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::TypeConstraint::DuckType::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 22µs | 2 | 13µs | # spent 11µs (8+3) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called:
# once (8µs+3µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 9 # spent 11µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9
# spent 3µs making 1 call to strict::import |
10 | 2 | 22µs | 2 | 29µs | # spent 18µs (8+11) within Moose::Meta::TypeConstraint::DuckType::BEGIN@10 which was called:
# once (8µs+11µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 10 # spent 18µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@10
# spent 11µs making 1 call to warnings::import |
11 | 2 | 28µs | 2 | 813µs | # spent 410µs (7+403) within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called:
# once (7µs+403µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 11 # spent 410µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11
# spent 403µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 27µs | 2 | 39µs | # spent 23µs (8+16) within Moose::Meta::TypeConstraint::DuckType::BEGIN@13 which was called:
# once (8µs+16µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 13 # spent 23µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@13
# spent 16µs making 1 call to Exporter::import |
14 | 2 | 25µs | 2 | 57µs | # spent 33µs (8+24) within Moose::Meta::TypeConstraint::DuckType::BEGIN@14 which was called:
# once (8µs+24µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 14 # spent 33µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@14
# spent 24µs making 1 call to Exporter::import |
15 | 2 | 27µs | 2 | 49µs | # spent 28µs (7+21) within Moose::Meta::TypeConstraint::DuckType::BEGIN@15 which was called:
# once (7µs+21µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 15 # spent 28µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@15
# spent 21µs making 1 call to Exporter::import |
16 | 2 | 28µs | 2 | 310µs | # spent 158µs (6+152) within Moose::Meta::TypeConstraint::DuckType::BEGIN@16 which was called:
# once (6µs+152µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 16 # spent 158µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@16
# spent 152µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
17 | |||||
18 | 2 | 22µs | 1 | 5µs | # spent 5µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@18 which was called:
# once (5µs+0s) by Moose::Util::TypeConstraints::BEGIN@39 at line 18 # spent 5µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@18 |
19 | |||||
20 | 2 | 492µs | 2 | 85µs | # spent 46µs (7+39) within Moose::Meta::TypeConstraint::DuckType::BEGIN@20 which was called:
# once (7µs+39µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 20 # spent 46µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@20
# spent 39µs making 1 call to base::import |
21 | |||||
22 | 1 | 4µs | 3 | 337µs | __PACKAGE__->meta->add_attribute('methods' => ( # spent 314µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 18µs making 1 call to Moose::Meta::TypeConstraint::DuckType::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
23 | accessor => 'methods', | ||||
24 | Class::MOP::_definition_context(), | ||||
25 | )); | ||||
26 | |||||
27 | my $inliner = sub { | ||||
28 | my $self = shift; | ||||
29 | my $val = shift; | ||||
30 | |||||
31 | return $self->parent->_inline_check($val) | ||||
32 | . ' && do {' . "\n" | ||||
33 | . 'my $val = ' . $val . ';' . "\n" | ||||
34 | . '&List::MoreUtils::all(' . "\n" | ||||
35 | . 'sub { $val->can($_) },' . "\n" | ||||
36 | . join(', ', map { B::perlstring($_) } @{ $self->methods }) | ||||
37 | . ');' . "\n" | ||||
38 | . '}'; | ||||
39 | 1 | 3µs | }; | ||
40 | |||||
41 | sub new { | ||||
42 | my ( $class, %args ) = @_; | ||||
43 | |||||
44 | $args{parent} | ||||
45 | = Moose::Util::TypeConstraints::find_type_constraint('Object'); | ||||
46 | |||||
47 | my @methods = @{ $args{methods} }; | ||||
48 | $args{constraint} = sub { | ||||
49 | my $val = $_[0]; | ||||
50 | return all { $val->can($_) } @methods; | ||||
51 | }; | ||||
52 | |||||
53 | $args{inlined} = $inliner; | ||||
54 | |||||
55 | my $self = $class->SUPER::new(\%args); | ||||
56 | |||||
57 | $self->compile_type_constraint() | ||||
58 | unless $self->_has_compiled_type_constraint; | ||||
59 | |||||
60 | return $self; | ||||
61 | } | ||||
62 | |||||
63 | sub equals { | ||||
64 | my ( $self, $type_or_name ) = @_; | ||||
65 | |||||
66 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
67 | |||||
68 | return unless $other->isa(__PACKAGE__); | ||||
69 | |||||
70 | my @self_methods = sort @{ $self->methods }; | ||||
71 | my @other_methods = sort @{ $other->methods }; | ||||
72 | |||||
73 | return unless @self_methods == @other_methods; | ||||
74 | |||||
75 | while ( @self_methods ) { | ||||
76 | my $method = shift @self_methods; | ||||
77 | my $other_method = shift @other_methods; | ||||
78 | |||||
79 | return unless $method eq $other_method; | ||||
80 | } | ||||
81 | |||||
82 | return 1; | ||||
83 | } | ||||
84 | |||||
85 | sub create_child_type { | ||||
86 | my ($self, @args) = @_; | ||||
87 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
88 | } | ||||
89 | |||||
90 | sub get_message { | ||||
91 | my $self = shift; | ||||
92 | my ($value) = @_; | ||||
93 | |||||
94 | if ($self->has_message) { | ||||
95 | return $self->SUPER::get_message(@_); | ||||
96 | } | ||||
97 | |||||
98 | return $self->SUPER::get_message($value) unless blessed($value); | ||||
99 | |||||
100 | my @methods = grep { !$value->can($_) } @{ $self->methods }; | ||||
101 | my $class = blessed $value; | ||||
102 | $class ||= $value; | ||||
103 | |||||
104 | return $class | ||||
105 | . " is missing methods " | ||||
106 | . english_list(map { "'$_'" } @methods); | ||||
107 | } | ||||
108 | |||||
109 | 1 | 6µs | 1; | ||
110 | |||||
111 | # ABSTRACT: Type constraint for duck typing | ||||
112 | |||||
113 | __END__ |