Profile of Moose/Meta/TypeConstraint/DuckType.pm

← Index
NYTProf Performance Profile «line view»
For script/ponapi
Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:11 2016

Filename | /usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint/DuckType.pm
Statements | Executed 23 statements in 712µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 16µs | 58µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@10Moose::Meta::TypeConstraint::DuckType::BEGIN@10
1 | 1 | 1 | 11µs | 26µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@4Moose::Meta::TypeConstraint::DuckType::BEGIN@4
1 | 1 | 1 | 8µs | 14µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@5Moose::Meta::TypeConstraint::DuckType::BEGIN@5
1 | 1 | 1 | 8µs | 26µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@8Moose::Meta::TypeConstraint::DuckType::BEGIN@8
1 | 1 | 1 | 7µs | 157µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@11Moose::Meta::TypeConstraint::DuckType::BEGIN@11
1 | 1 | 1 | 7µs | 31µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@15Moose::Meta::TypeConstraint::DuckType::BEGIN@15
1 | 1 | 1 | 7µs | 30µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@9Moose::Meta::TypeConstraint::DuckType::BEGIN@9
1 | 1 | 1 | 6µs | 439µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@6Moose::Meta::TypeConstraint::DuckType::BEGIN@6
1 | 1 | 1 | 4µs | 4µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@13Moose::Meta::TypeConstraint::DuckType::BEGIN@13
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:34]Moose::Meta::TypeConstraint::DuckType::__ANON__[:34]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:45]Moose::Meta::TypeConstraint::DuckType::__ANON__[:45]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:46]Moose::Meta::TypeConstraint::DuckType::__ANON__[:46]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::create_child_typeMoose::Meta::TypeConstraint::DuckType::create_child_type
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::equalsMoose::Meta::TypeConstraint::DuckType::equals
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::get_messageMoose::Meta::TypeConstraint::DuckType::get_message
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::newMoose::Meta::TypeConstraint::DuckType::new

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Moose::Meta::TypeConstraint::DuckType;
2 | 1 | 500ns |  |  | our $VERSION = '2.1604';
3 |  |  |  |  |
4 | 2 | 23µs | 2 | 41µs | # spent 26µs (11+15) within Moose::Meta::TypeConstraint::DuckType::BEGIN@4 which was called: # once (11µs+15µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 4 use strict; # spent 26µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@4 # spent 15µs making 1 call to strict::import
5 | 2 | 21µs | 2 | 21µs | # spent 14µs (8+7) within Moose::Meta::TypeConstraint::DuckType::BEGIN@5 which was called: # once (8µs+7µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 5 use warnings; # spent 14µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@5 # spent 6µs making 1 call to warnings::import
6 | 2 | 26µs | 2 | 871µs | # spent 439µs (6+432) within Moose::Meta::TypeConstraint::DuckType::BEGIN@6 which was called: # once (6µs+432µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 6 use metaclass; # spent 439µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@6 # spent 432µs making 1 call to metaclass::import
7 |  |  |  |  |
8 | 2 | 24µs | 2 | 43µs | # spent 26µs (8+18) within Moose::Meta::TypeConstraint::DuckType::BEGIN@8 which was called: # once (8µs+18µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 8 use B; # spent 26µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@8 # spent 18µs making 1 call to Exporter::import
9 | 2 | 32µs | 2 | 53µs | # spent 30µs (7+23) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called: # once (7µs+23µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 9 use Scalar::Util 'blessed'; # spent 30µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9 # spent 23µs making 1 call to Exporter::import
10 | 3 | 44µs | 3 | 82µs | # spent 58µs (16+42) within Moose::Meta::TypeConstraint::DuckType::BEGIN@10 which was called: # once (16µs+42µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 10 use List::Util 1.33 qw(all); # spent 58µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@10 # spent 13µs making 1 call to UNIVERSAL::VERSION # spent 10µs making 1 call to List::Util::import
11 | 2 | 25µs | 2 | 308µs | # spent 157µs (7+150) within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called: # once (7µs+150µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 11 use Moose::Util 'english_list'; # spent 157µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11 # spent 150µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
12 |  |  |  |  |
13 | 2 | 20µ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 use Moose::Util::TypeConstraints (); # spent 4µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@13
14 |  |  |  |  |
15 | 2 | 481µs | 2 | 56µs | # spent 31µs (7+24) within Moose::Meta::TypeConstraint::DuckType::BEGIN@15 which was called: # once (7µs+24µs) by Moose::Util::TypeConstraints::BEGIN@31 at line 15 use parent 'Moose::Meta::TypeConstraint'; # spent 31µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@15 # spent 24µs making 1 call to parent::import
16 |  |  |  |  |
17 | 1 | 6µs | 3 | 342µs | __PACKAGE__->meta->add_attribute('methods' => ( # spent 321µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 15µ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 | 3µ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 | 5µs |  |  | 1;
105 |  |  |  |  |
106 |  |  |  |  | # ABSTRACT: Type constraint for duck typing
107 |  |  |  |  |
108 |  |  |  |  | __END__