Filename | /Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint/DuckType.pm |
Statements | Executed 23 statements in 729µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 20µs | 62µs | BEGIN@10 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 14µs | 28µs | BEGIN@4 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 13µs | 28µs | BEGIN@8 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 13µs | 37µs | BEGIN@15 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 9µs | 34µs | BEGIN@9 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 8µs | 164µs | BEGIN@11 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 8µs | 12µs | BEGIN@5 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 7µs | 477µs | BEGIN@6 | Moose::Meta::TypeConstraint::DuckType::
1 | 1 | 1 | 4µs | 4µ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 | 700ns | our $VERSION = '2.1403'; | ||
3 | |||||
4 | 2 | 24µs | 2 | 43µs | # spent 28µs (14+14) within Moose::Meta::TypeConstraint::DuckType::BEGIN@4 which was called:
# once (14µs+14µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 4 # spent 28µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@4
# spent 14µs making 1 call to strict::import |
5 | 2 | 21µs | 2 | 16µs | # spent 12µs (8+4) within Moose::Meta::TypeConstraint::DuckType::BEGIN@5 which was called:
# once (8µs+4µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 5 # spent 12µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@5
# spent 4µs making 1 call to warnings::import |
6 | 2 | 25µs | 2 | 947µs | # spent 477µs (7+470) within Moose::Meta::TypeConstraint::DuckType::BEGIN@6 which was called:
# once (7µs+470µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 6 # spent 477µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@6
# spent 470µs making 1 call to metaclass::import |
7 | |||||
8 | 2 | 24µs | 2 | 43µs | # spent 28µs (13+15) within Moose::Meta::TypeConstraint::DuckType::BEGIN@8 which was called:
# once (13µs+15µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 8 # spent 28µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@8
# spent 15µs making 1 call to Exporter::import |
9 | 2 | 34µs | 2 | 59µs | # spent 34µs (9+25) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called:
# once (9µs+25µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 9 # spent 34µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9
# spent 25µs making 1 call to Exporter::import |
10 | 3 | 47µs | 3 | 86µs | # spent 62µs (20+43) within Moose::Meta::TypeConstraint::DuckType::BEGIN@10 which was called:
# once (20µs+43µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 10 # spent 62µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@10
# spent 14µs making 1 call to UNIVERSAL::VERSION
# spent 10µs making 1 call to List::Util::import |
11 | 2 | 35µs | 2 | 321µs | # spent 164µs (8+156) within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called:
# once (8µs+156µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 11 # spent 164µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11
# spent 156µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
12 | |||||
13 | 2 | 27µs | 1 | 4µs | # spent 4µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@13 which was called:
# once (4µs+0s) by Moose::Util::TypeConstraints::BEGIN@31 at line 13 # spent 4µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@13 |
14 | |||||
15 | 2 | 476µs | 2 | 62µs | # spent 37µs (13+25) within Moose::Meta::TypeConstraint::DuckType::BEGIN@15 which was called:
# once (13µs+25µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 15 # spent 37µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@15
# spent 25µs making 1 call to parent::import |
16 | |||||
17 | 1 | 6µs | 3 | 366µs | __PACKAGE__->meta->add_attribute('methods' => ( # spent 343µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::DuckType::meta
# spent 6µ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 | 2µ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 | 6µs | 1; | ||
105 | |||||
106 | # ABSTRACT: Type constraint for duck typing | ||||
107 | |||||
108 | __END__ |