Profile of Moose/Meta/TypeConstraint/DuckType.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:49 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint/DuckType.pm
Statements | Executed 33 statements in 746µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 10µs | 10µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@2Moose::Meta::TypeConstraint::DuckType::BEGIN@2
1 | 1 | 1 | 10µs | 34µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@13Moose::Meta::TypeConstraint::DuckType::BEGIN@13
1 | 1 | 1 | 9µs | 14µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@9Moose::Meta::TypeConstraint::DuckType::BEGIN@9
1 | 1 | 1 | 9µs | 559µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@11Moose::Meta::TypeConstraint::DuckType::BEGIN@11
1 | 1 | 1 | 8µs | 223µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@16Moose::Meta::TypeConstraint::DuckType::BEGIN@16
1 | 1 | 1 | 8µs | 25µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@10Moose::Meta::TypeConstraint::DuckType::BEGIN@10
1 | 1 | 1 | 8µs | 28µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@15Moose::Meta::TypeConstraint::DuckType::BEGIN@15
1 | 1 | 1 | 8µs | 84µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@20Moose::Meta::TypeConstraint::DuckType::BEGIN@20
1 | 1 | 1 | 7µs | 35µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@14Moose::Meta::TypeConstraint::DuckType::BEGIN@14
1 | 1 | 1 | 4µs | 4µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@18Moose::Meta::TypeConstraint::DuckType::BEGIN@18
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:39]Moose::Meta::TypeConstraint::DuckType::__ANON__[:39]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:50]Moose::Meta::TypeConstraint::DuckType::__ANON__[:50]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:51]Moose::Meta::TypeConstraint::DuckType::__ANON__[:51]
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 |  |  |  |  | # spent 10µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@2 which was called: # once (10µs+0s) by Moose::Util::TypeConstraints::BEGIN@39 at line 4 BEGIN {
3 | 1 | 11µs |  |  | $Moose::Meta::TypeConstraint::DuckType::AUTHORITY = 'cpan:STEVAN';
4 | 1 | 25µs | 1 | 10µs | } # spent 10µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@2
5 |  |  |  |  | {
6 | 2 | 1µs |  |  | $Moose::Meta::TypeConstraint::DuckType::VERSION = '2.0602';
7 |  |  |  |  | }
8 |  |  |  |  |
9 | 3 | 19µs | 2 | 19µs | # spent 14µs (9+5) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called: # once (9µs+5µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 9 use strict; # spent 14µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9 # spent 5µs making 1 call to strict::import
10 | 3 | 22µs | 2 | 41µs | # spent 25µs (8+16) within Moose::Meta::TypeConstraint::DuckType::BEGIN@10 which was called: # once (8µs+16µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 10 use warnings; # spent 25µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@10 # spent 16µs making 1 call to warnings::import
11 | 3 | 28µs | 2 | 1.11ms | # spent 559µs (9+550) within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called: # once (9µs+550µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 11 use metaclass; # spent 559µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11 # spent 550µs making 1 call to metaclass::import
12 |  |  |  |  |
13 | 3 | 27µs | 2 | 59µs | # spent 34µs (10+25) within Moose::Meta::TypeConstraint::DuckType::BEGIN@13 which was called: # once (10µs+25µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 13 use B; # spent 34µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@13 # spent 25µs making 1 call to Exporter::import
14 | 3 | 22µs | 2 | 63µs | # spent 35µs (7+28) within Moose::Meta::TypeConstraint::DuckType::BEGIN@14 which was called: # once (7µs+28µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 14 use Scalar::Util 'blessed'; # spent 35µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@14 # spent 28µs making 1 call to Exporter::import
15 | 3 | 19µs | 2 | 48µs | # spent 28µs (8+20) within Moose::Meta::TypeConstraint::DuckType::BEGIN@15 which was called: # once (8µs+20µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 15 use List::MoreUtils qw(all); # spent 28µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@15 # spent 20µs making 1 call to Exporter::import
16 | 3 | 24µs | 2 | 438µs | # spent 223µs (8+215) within Moose::Meta::TypeConstraint::DuckType::BEGIN@16 which was called: # once (8µs+215µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 16 use Moose::Util 'english_list'; # spent 223µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@16 # spent 215µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
17 |  |  |  |  |
18 | 3 | 18µs | 1 | 4µs | # spent 4µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@18 which was called: # once (4µs+0s) by Moose::Util::TypeConstraints::BEGIN@39 at line 18 use Moose::Util::TypeConstraints (); # spent 4µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@18
19 |  |  |  |  |
20 | 3 | 513µs | 2 | 161µs | # spent 84µs (8+76) within Moose::Meta::TypeConstraint::DuckType::BEGIN@20 which was called: # once (8µs+76µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 20 use base 'Moose::Meta::TypeConstraint'; # spent 84µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@20 # spent 76µs making 1 call to base::import
21 |  |  |  |  |
22 | 1 | 6µs | 3 | 490µs | __PACKAGE__->meta->add_attribute('methods' => ( # spent 459µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 23µs making 1 call to Moose::Meta::TypeConstraint::DuckType::meta # spent 8µ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 | 2µ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 | 8µs |  |  | 1;
110 |  |  |  |  |
111 |  |  |  |  | # ABSTRACT: Type constraint for duck typing
112 |  |  |  |  |
- - |  |  |  |  |
115 |  |  |  |  | =pod
116 |  |  |  |  |
117 |  |  |  |  | =head1 NAME
118 |  |  |  |  |
119 |  |  |  |  | Moose::Meta::TypeConstraint::DuckType - Type constraint for duck typing
120 |  |  |  |  |
121 |  |  |  |  | =head1 VERSION
122 |  |  |  |  |
123 |  |  |  |  | version 2.0602
124 |  |  |  |  |
125 |  |  |  |  | =head1 DESCRIPTION
126 |  |  |  |  |
127 |  |  |  |  | This class represents type constraints based on an enumerated list of
128 |  |  |  |  | required methods.
129 |  |  |  |  |
130 |  |  |  |  | =head1 INHERITANCE
131 |  |  |  |  |
132 |  |  |  |  | C<Moose::Meta::TypeConstraint::DuckType> is a subclass of
133 |  |  |  |  | L<Moose::Meta::TypeConstraint>.
134 |  |  |  |  |
135 |  |  |  |  | =head1 METHODS
136 |  |  |  |  |
137 |  |  |  |  | =over 4
138 |  |  |  |  |
139 |  |  |  |  | =item B<< Moose::Meta::TypeConstraint::DuckType->new(%options) >>
140 |  |  |  |  |
141 |  |  |  |  | This creates a new duck type constraint based on the given
142 |  |  |  |  | C<%options>.
143 |  |  |  |  |
144 |  |  |  |  | It takes the same options as its parent, with several
145 |  |  |  |  | exceptions. First, it requires an additional option, C<methods>. This
146 |  |  |  |  | should be an array reference containing a list of required method
147 |  |  |  |  | names. Second, it automatically sets the parent to the C<Object> type.
148 |  |  |  |  |
149 |  |  |  |  | Finally, it ignores any provided C<constraint> option. The constraint
150 |  |  |  |  | is generated automatically based on the provided C<methods>.
151 |  |  |  |  |
152 |  |  |  |  | =item B<< $constraint->methods >>
153 |  |  |  |  |
154 |  |  |  |  | Returns the array reference of required methods provided to the
155 |  |  |  |  | constructor.
156 |  |  |  |  |
157 |  |  |  |  | =item B<< $constraint->create_child_type >>
158 |  |  |  |  |
159 |  |  |  |  | This returns a new L<Moose::Meta::TypeConstraint> object with the type
160 |  |  |  |  | as its parent.
161 |  |  |  |  |
162 |  |  |  |  | Note that it does I<not> return a C<Moose::Meta::TypeConstraint::DuckType>
163 |  |  |  |  | object!
164 |  |  |  |  |
165 |  |  |  |  | =back
166 |  |  |  |  |
167 |  |  |  |  | =head1 BUGS
168 |  |  |  |  |
169 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
170 |  |  |  |  |
171 |  |  |  |  | =head1 AUTHOR
172 |  |  |  |  |
173 |  |  |  |  | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
174 |  |  |  |  |
175 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
176 |  |  |  |  |
177 |  |  |  |  | This software is copyright (c) 2012 by Infinity Interactive, Inc..
178 |  |  |  |  |
179 |  |  |  |  | This is free software; you can redistribute it and/or modify it under
180 |  |  |  |  | the same terms as the Perl 5 programming language system itself.
181 |  |  |  |  |
182 |  |  |  |  | =cut
183 |  |  |  |  |
184 |  |  |  |  |
185 |  |  |  |  | __END__