| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint/DuckType.pm |
| Statements | Executed 29 statements in 2.96ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 75µs | 92µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@3 |
| 1 | 1 | 1 | 57µs | 3.04ms | Moose::Meta::TypeConstraint::DuckType::BEGIN@5 |
| 1 | 1 | 1 | 41µs | 204µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@7 |
| 1 | 1 | 1 | 41µs | 186µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@8 |
| 1 | 1 | 1 | 40µs | 299µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@17 |
| 1 | 1 | 1 | 38µs | 108µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@4 |
| 1 | 1 | 1 | 38µs | 915µs | Moose::Meta::TypeConstraint::DuckType::BEGIN@9 |
| 1 | 1 | 1 | 23µs | 23µ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 | 106µs | 2 | 110µs | # spent 92µs (75+18) within Moose::Meta::TypeConstraint::DuckType::BEGIN@3 which was called:
# once (75µs+18µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 3 # spent 92µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@3
# spent 18µs making 1 call to strict::import |
| 4 | 3 | 95µs | 2 | 177µs | # spent 108µs (38+69) within Moose::Meta::TypeConstraint::DuckType::BEGIN@4 which was called:
# once (38µs+69µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 4 # spent 108µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@4
# spent 69µs making 1 call to warnings::import |
| 5 | 3 | 154µs | 2 | 6.03ms | # spent 3.04ms (57µs+2.99) within Moose::Meta::TypeConstraint::DuckType::BEGIN@5 which was called:
# once (57µs+2.99ms) by Moose::Util::TypeConstraints::BEGIN@36 at line 5 # spent 3.04ms making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@5
# spent 2.99ms making 1 call to metaclass::import |
| 6 | |||||
| 7 | 3 | 197µs | 2 | 368µs | # spent 204µs (41+163) within Moose::Meta::TypeConstraint::DuckType::BEGIN@7 which was called:
# once (41µs+163µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 7 # spent 204µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@7
# spent 163µs making 1 call to Exporter::import |
| 8 | 3 | 107µs | 2 | 332µs | # spent 186µs (41+146) within Moose::Meta::TypeConstraint::DuckType::BEGIN@8 which was called:
# once (41µs+146µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 8 # spent 186µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@8
# spent 146µs making 1 call to Exporter::import |
| 9 | 3 | 133µs | 2 | 1.79ms | # spent 915µs (38+877) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called:
# once (38µs+877µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 9 # spent 915µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9
# spent 877µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] |
| 10 | |||||
| 11 | 3 | 227µs | 1 | 23µs | # spent 23µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called:
# once (23µs+0s) by Moose::Util::TypeConstraints::BEGIN@36 at line 11 # spent 23µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11 |
| 12 | |||||
| 13 | 1 | 6µs | our $VERSION = '1.19'; | ||
| 14 | 1 | 64µs | $VERSION = eval $VERSION; # spent 12µs executing statements in string eval | ||
| 15 | 1 | 3µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 16 | |||||
| 17 | 3 | 1.81ms | 2 | 557µs | # spent 299µs (40+259) within Moose::Meta::TypeConstraint::DuckType::BEGIN@17 which was called:
# once (40µs+259µs) by Moose::Util::TypeConstraints::BEGIN@36 at line 17 # spent 299µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@17
# spent 259µs making 1 call to base::import |
| 18 | |||||
| 19 | 1 | 28µs | 2 | 2.19ms | __PACKAGE__->meta->add_attribute('methods' => ( # spent 2.07ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 119µ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 | 26µs | 1; | ||
| 104 | |||||
| 105 | __END__ |