Profile of /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/DuckType.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For 01.HTTP.t
Run on Tue May 4 15:25:55 2010
Reported on Tue May 4 15:26:04 2010

File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/DuckType.pm
Statements Executed | 29
Statement Execution Time | 588µs

Subroutines — ordered by exclusive time
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 13µs | 16µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@3Moose::Meta::TypeConstraint::DuckType::BEGIN@3
1 | 1 | 1 | 8µs | 186µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@9Moose::Meta::TypeConstraint::DuckType::BEGIN@9
1 | 1 | 1 | 7µs | 16µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@4Moose::Meta::TypeConstraint::DuckType::BEGIN@4
1 | 1 | 1 | 7µs | 29µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@8Moose::Meta::TypeConstraint::DuckType::BEGIN@8
1 | 1 | 1 | 7µs | 54µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@17Moose::Meta::TypeConstraint::DuckType::BEGIN@17
1 | 1 | 1 | 6µs | 31µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@7Moose::Meta::TypeConstraint::DuckType::BEGIN@7
1 | 1 | 1 | 6µs | 103µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@5Moose::Meta::TypeConstraint::DuckType::BEGIN@5
1 | 1 | 1 | 4µs | 4µs | Moose::Meta::TypeConstraint::DuckType::::BEGIN@11Moose::Meta::TypeConstraint::DuckType::BEGIN@11
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:65]Moose::Meta::TypeConstraint::DuckType::__ANON__[:65]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:66]Moose::Meta::TypeConstraint::DuckType::__ANON__[:66]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:79]Moose::Meta::TypeConstraint::DuckType::__ANON__[:79]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::__ANON__[:80]Moose::Meta::TypeConstraint::DuckType::__ANON__[:80]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::DuckType::_compile_hand_optimized_type_constraint
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::DuckType::::constraintMoose::Meta::TypeConstraint::DuckType::constraint
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 |  |  |  |  |
3 | 3 | 20µs | 2 | 19µs | # spent 16µs (13+3) within Moose::Meta::TypeConstraint::DuckType::BEGIN@3 which was called # once (13µs+3µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 3 use strict; # spent 16µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@3 # spent 3µs making 1 call to strict::import
4 | 3 | 18µs | 2 | 24µs | # spent 16µs (7+9) within Moose::Meta::TypeConstraint::DuckType::BEGIN@4 which was called # once (7µs+9µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 4 use warnings; # spent 16µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@4 # spent 9µs making 1 call to warnings::import
5 | 3 | 25µs | 2 | 201µs | # spent 103µs (6+98) within Moose::Meta::TypeConstraint::DuckType::BEGIN@5 which was called # once (6µs+98µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 5 use metaclass; # spent 103µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@5 # spent 98µs making 1 call to metaclass::import
6 |  |  |  |  |
7 | 3 | 24µs | 2 | 55µs | # spent 31µs (6+24) within Moose::Meta::TypeConstraint::DuckType::BEGIN@7 which was called # once (6µs+24µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 7 use Scalar::Util 'blessed'; # spent 31µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@7 # spent 24µs making 1 call to Exporter::import
8 | 3 | 22µs | 2 | 51µs | # spent 29µs (7+22) within Moose::Meta::TypeConstraint::DuckType::BEGIN@8 which was called # once (7µs+22µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 8 use List::MoreUtils qw(all); # spent 29µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@8 # spent 22µs making 1 call to Exporter::import
9 | 3 | 28µs | 2 | 364µs | # spent 186µs (8+178) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called # once (8µs+178µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 9 use Moose::Util 'english_list'; # spent 186µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9 # spent 178µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
10 |  |  |  |  |
11 | 3 | 41µs | 1 | 4µs | # spent 4µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called # once (4µs+0s) by Moose::Util::TypeConstraints::BEGIN@35 at line 11 use Moose::Util::TypeConstraints (); # spent 4µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11
12 |  |  |  |  |
13 | 1 | 700ns |  |  | our $VERSION = '0.98';
14 | 1 | 19µs |  |  | $VERSION = eval $VERSION;
15 | 1 | 400ns |  |  | our $AUTHORITY = 'cpan:STEVAN';
16 |  |  |  |  |
17 | 3 | 374µs | 2 | 101µs | # spent 54µs (7+47) within Moose::Meta::TypeConstraint::DuckType::BEGIN@17 which was called # once (7µs+47µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 17 use base 'Moose::Meta::TypeConstraint'; # spent 54µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@17 # spent 47µs making 1 call to base::import
18 |  |  |  |  |
19 | 1 | 3µs | 2 | 278µs | __PACKAGE__->meta->add_attribute('methods' => ( # spent 262µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 16µ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 | 12µs |  |  | 1;
104 |  |  |  |  |
105 |  |  |  |  | __END__
106 |  |  |  |  |
107 |  |  |  |  | =pod
108 |  |  |  |  |
109 |  |  |  |  | =head1 NAME
110 |  |  |  |  |
111 |  |  |  |  | Moose::Meta::TypeConstraint::DuckType - Type constraint for duck typing
112 |  |  |  |  |
113 |  |  |  |  | =head1 DESCRIPTION
114 |  |  |  |  |
115 |  |  |  |  | This class represents type constraints based on an enumerated list of
116 |  |  |  |  | required methods.
117 |  |  |  |  |
118 |  |  |  |  | =head1 INHERITANCE
119 |  |  |  |  |
120 |  |  |  |  | C<Moose::Meta::TypeConstraint::DuckType> is a subclass of
121 |  |  |  |  | L<Moose::Meta::TypeConstraint>.
122 |  |  |  |  |
123 |  |  |  |  | =head1 METHODS
124 |  |  |  |  |
125 |  |  |  |  | =over 4
126 |  |  |  |  |
127 |  |  |  |  | =item B<< Moose::Meta::TypeConstraint::DuckType->new(%options) >>
128 |  |  |  |  |
129 |  |  |  |  | This creates a new duck type constraint based on the given
130 |  |  |  |  | C<%options>.
131 |  |  |  |  |
132 |  |  |  |  | It takes the same options as its parent, with several
133 |  |  |  |  | exceptions. First, it requires an additional option, C<methods>. This
134 |  |  |  |  | should be an array reference containing a list of required method
135 |  |  |  |  | names. Second, it automatically sets the parent to the C<Object> type.
136 |  |  |  |  |
137 |  |  |  |  | Finally, it ignores any provided C<constraint> option. The constraint
138 |  |  |  |  | is generated automatically based on the provided C<methods>.
139 |  |  |  |  |
140 |  |  |  |  | =item B<< $constraint->methods >>
141 |  |  |  |  |
142 |  |  |  |  | Returns the array reference of required methods provided to the
143 |  |  |  |  | constructor.
144 |  |  |  |  |
145 |  |  |  |  | =item B<< $constraint->create_child_type >>
146 |  |  |  |  |
147 |  |  |  |  | This returns a new L<Moose::Meta::TypeConstraint> object with the type
148 |  |  |  |  | as its parent.
149 |  |  |  |  |
150 |  |  |  |  | Note that it does I<not> return a C<Moose::Meta::TypeConstraint::DuckType>
151 |  |  |  |  | object!
152 |  |  |  |  |
153 |  |  |  |  | =back
154 |  |  |  |  |
155 |  |  |  |  | =head1 BUGS
156 |  |  |  |  |
157 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
158 |  |  |  |  |
159 |  |  |  |  | =head1 AUTHOR
160 |  |  |  |  |
161 |  |  |  |  | Chris Prather E<lt>chris@prather.orgE<gt>
162 |  |  |  |  |
163 |  |  |  |  | Shawn M Moore E<lt>sartak@gmail.comE<gt>
164 |  |  |  |  |
165 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
166 |  |  |  |  |
167 |  |  |  |  | Copyright 2006-2010 by Infinity Interactive, Inc.
168 |  |  |  |  |
169 |  |  |  |  | L<http://www.iinteractive.com>
170 |  |  |  |  |
171 |  |  |  |  | This library is free software; you can redistribute it and/or modify
172 |  |  |  |  | it under the same terms as Perl itself.
173 |  |  |  |  |
174 |  |  |  |  | =cut
175 |  |  |  |  |