| Filename | /home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint/DuckType.pm |
| Statements | Executed 29 statements in 2.79ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 72µs | 90µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@3 |
| 1 | 1 | 1 | 41µs | 203µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@7 |
| 1 | 1 | 1 | 41µs | 1.01ms | Moose::Meta::TypeConstraint::DuckType::BEGIN@9 |
| 1 | 1 | 1 | 40µs | 171µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@8 |
| 1 | 1 | 1 | 40µs | 307µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@17 |
| 1 | 1 | 1 | 39µs | 106µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@4 |
| 1 | 1 | 1 | 38µs | 2.71ms | Moose::Meta::TypeConstraint::DuckType::BEGIN@5 |
| 1 | 1 | 1 | 24µs | 24µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@11 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::__ANON__[:65] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::__ANON__[:66] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::__ANON__[:79] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::__ANON__[:80] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::_compile_hand_optimized_type_constraint |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::constraint |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::create_child_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::equals |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::get_message |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::new |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::TypeConstraint::DuckType; | ||||
| 2 | |||||
| 3 | 3 | 107µs | 2 | 109µs | # spent 90µs (72+18) within Moose::Meta::TypeConstraint::DuckType::BEGIN@3 which was called:
# once (72µs+18µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 3 # spent 90µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@3
# spent 18µs making 1 call to strict::import |
| 4 | 3 | 96µs | 2 | 173µs | # spent 106µs (39+67) within Moose::Meta::TypeConstraint::DuckType::BEGIN@4 which was called:
# once (39µs+67µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 4 # spent 106µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@4
# spent 67µs making 1 call to warnings::import |
| 5 | 3 | 142µs | 2 | 5.39ms | # spent 2.71ms (38µs+2.68) within Moose::Meta::TypeConstraint::DuckType::BEGIN@5 which was called:
# once (38µs+2.68ms) by Moose::Util::TypeConstraints::BEGIN@36 at line 5 # spent 2.71ms making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@5
# spent 2.68ms making 1 call to metaclass::import |
| 6 | |||||
| 7 | 3 | 115µs | 2 | 365µs | # spent 203µs (41+162) within Moose::Meta::TypeConstraint::DuckType::BEGIN@7 which was called:
# once (41µs+162µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 7 # spent 203µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@7
# spent 162µs making 1 call to Exporter::import |
| 8 | 3 | 131µs | 2 | 302µs | # spent 171µs (40+131) within Moose::Meta::TypeConstraint::DuckType::BEGIN@8 which was called:
# once (40µs+131µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 8 # spent 171µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@8
# spent 131µs making 1 call to Exporter::import |
| 9 | 3 | 141µs | 2 | 1.98ms | # spent 1.01ms (41µs+970µs) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called:
# once (41µs+970µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 9 # spent 1.01ms making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9
# spent 970µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 10 | |||||
| 11 | 3 | 209µs | 1 | 24µs | # spent 24µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called:
# once (24µs+0s) by Moose::Util::TypeConstraints::BEGIN@36 at line 11 # spent 24µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11 |
| 12 | |||||
| 13 | 1 | 6µs | our $VERSION = '1.19'; | ||
| 14 | 1 | 66µs | $VERSION = eval $VERSION; # spent 12µs executing statements in string eval | ||
| 15 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 16 | |||||
| 17 | 3 | 1.73ms | 2 | 573µs | # spent 307µs (40+266) within Moose::Meta::TypeConstraint::DuckType::BEGIN@17 which was called:
# once (40µs+266µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 17 # spent 307µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@17
# spent 266µs making 1 call to base::import |
| 18 | |||||
| 19 | 1 | 28µs | 2 | 2.14ms | __PACKAGE__->meta->add_attribute('methods' => ( # spent 2.02ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 122µs making 1 call to Moose::Meta::TypeConstraint::DuckType::meta |
| 20 | accessor => 'methods', | ||||
| 21 | )); | ||||
| 22 | |||||
| 23 | sub new { | ||||
| 24 | my ( $class, %args ) = @_; | ||||
| 25 | |||||
| 26 | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); | ||||
| 27 | |||||
| 28 | my $self = $class->_new(\%args); | ||||
| 29 | |||||
| 30 | $self->compile_type_constraint() | ||||
| 31 | unless $self->_has_compiled_type_constraint; | ||||
| 32 | |||||
| 33 | return $self; | ||||
| 34 | } | ||||
| 35 | |||||
| 36 | sub equals { | ||||
| 37 | my ( $self, $type_or_name ) = @_; | ||||
| 38 | |||||
| 39 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 40 | |||||
| 41 | return unless $other->isa(__PACKAGE__); | ||||
| 42 | |||||
| 43 | my @self_methods = sort @{ $self->methods }; | ||||
| 44 | my @other_methods = sort @{ $other->methods }; | ||||
| 45 | |||||
| 46 | return unless @self_methods == @other_methods; | ||||
| 47 | |||||
| 48 | while ( @self_methods ) { | ||||
| 49 | my $method = shift @self_methods; | ||||
| 50 | my $other_method = shift @other_methods; | ||||
| 51 | |||||
| 52 | return unless $method eq $other_method; | ||||
| 53 | } | ||||
| 54 | |||||
| 55 | return 1; | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | sub constraint { | ||||
| 59 | my $self = shift; | ||||
| 60 | |||||
| 61 | my @methods = @{ $self->methods }; | ||||
| 62 | |||||
| 63 | return sub { | ||||
| 64 | my $obj = shift; | ||||
| 65 | return all { $obj->can($_) } @methods | ||||
| 66 | }; | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | sub _compile_hand_optimized_type_constraint { | ||||
| 70 | my $self = shift; | ||||
| 71 | |||||
| 72 | my @methods = @{ $self->methods }; | ||||
| 73 | |||||
| 74 | sub { | ||||
| 75 | my $obj = shift; | ||||
| 76 | |||||
| 77 | return blessed($obj) | ||||
| 78 | && blessed($obj) ne 'Regexp' | ||||
| 79 | && all { $obj->can($_) } @methods; | ||||
| 80 | }; | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | sub create_child_type { | ||||
| 84 | my ($self, @args) = @_; | ||||
| 85 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
| 86 | } | ||||
| 87 | |||||
| 88 | sub get_message { | ||||
| 89 | my $self = shift; | ||||
| 90 | my ($value) = @_; | ||||
| 91 | |||||
| 92 | if ($self->has_message) { | ||||
| 93 | return $self->SUPER::get_message(@_); | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | my @methods = grep { !$value->can($_) } @{ $self->methods }; | ||||
| 97 | my $class = blessed $value; | ||||
| 98 | return $class | ||||
| 99 | . " is missing methods " | ||||
| 100 | . english_list(map { "'$_'" } @methods); | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | 1 | 24µs | 1; | ||
| 104 | |||||
| 105 | __END__ |