← Index
NYTProf Performance Profile   « line view »
For examples/Atom-timer.pl
  Run on Mon Aug 12 14:45:28 2013
Reported on Mon Aug 12 14:46:14 2013

Filename/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/DuckType.pm
StatementsExecuted 24 statements in 700µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11110µs10µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@2Moose::Meta::TypeConstraint::DuckType::BEGIN@2
1117µs19µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@13Moose::Meta::TypeConstraint::DuckType::BEGIN@13
1117µs10µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@10Moose::Meta::TypeConstraint::DuckType::BEGIN@10
1116µs23µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@15Moose::Meta::TypeConstraint::DuckType::BEGIN@15
1116µs160µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@16Moose::Meta::TypeConstraint::DuckType::BEGIN@16
1116µs16µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@9Moose::Meta::TypeConstraint::DuckType::BEGIN@9
1116µs3.72msMoose::Meta::TypeConstraint::DuckType::::BEGIN@11Moose::Meta::TypeConstraint::DuckType::BEGIN@11
1116µs25µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@14Moose::Meta::TypeConstraint::DuckType::BEGIN@14
1116µs52µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@20Moose::Meta::TypeConstraint::DuckType::BEGIN@20
1113µs3µsMoose::Meta::TypeConstraint::DuckType::::BEGIN@18Moose::Meta::TypeConstraint::DuckType::BEGIN@18
0000s0sMoose::Meta::TypeConstraint::DuckType::::__ANON__[:39]Moose::Meta::TypeConstraint::DuckType::__ANON__[:39]
0000s0sMoose::Meta::TypeConstraint::DuckType::::__ANON__[:50]Moose::Meta::TypeConstraint::DuckType::__ANON__[:50]
0000s0sMoose::Meta::TypeConstraint::DuckType::::__ANON__[:51]Moose::Meta::TypeConstraint::DuckType::__ANON__[:51]
0000s0sMoose::Meta::TypeConstraint::DuckType::::create_child_typeMoose::Meta::TypeConstraint::DuckType::create_child_type
0000s0sMoose::Meta::TypeConstraint::DuckType::::equalsMoose::Meta::TypeConstraint::DuckType::equals
0000s0sMoose::Meta::TypeConstraint::DuckType::::get_messageMoose::Meta::TypeConstraint::DuckType::get_message
0000s0sMoose::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
1package 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 {
314µs $Moose::Meta::TypeConstraint::DuckType::AUTHORITY = 'cpan:STEVAN';
4128µs110µs}
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@2
5{
62700ns $Moose::Meta::TypeConstraint::DuckType::VERSION = '2.1005';
7}
8
9224µs226µs
# spent 16µs (6+10) within Moose::Meta::TypeConstraint::DuckType::BEGIN@9 which was called: # once (6µs+10µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 9
use strict;
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@9 # spent 10µs making 1 call to strict::import
10219µs213µs
# spent 10µs (7+3) within Moose::Meta::TypeConstraint::DuckType::BEGIN@10 which was called: # once (7µs+3µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 10
use warnings;
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@10 # spent 3µs making 1 call to warnings::import
11226µs27.43ms
# spent 3.72ms (6µs+3.71) within Moose::Meta::TypeConstraint::DuckType::BEGIN@11 which was called: # once (6µs+3.71ms) by Moose::Util::TypeConstraints::BEGIN@39 at line 11
use metaclass;
# spent 3.72ms making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@11 # spent 3.71ms making 1 call to metaclass::import
12
13223µs232µs
# spent 19µs (7+12) within Moose::Meta::TypeConstraint::DuckType::BEGIN@13 which was called: # once (7µs+12µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 13
use B;
# spent 19µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@13 # spent 12µs making 1 call to Exporter::import
14223µs244µs
# spent 25µs (6+19) within Moose::Meta::TypeConstraint::DuckType::BEGIN@14 which was called: # once (6µs+19µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 14
use Scalar::Util 'blessed';
# spent 25µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@14 # spent 19µs making 1 call to Exporter::import
15226µs240µs
# spent 23µs (6+17) within Moose::Meta::TypeConstraint::DuckType::BEGIN@15 which was called: # once (6µs+17µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 15
use List::MoreUtils qw(all);
# spent 23µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@15 # spent 17µs making 1 call to Exporter::import
16225µs2314µs
# spent 160µs (6+154) within Moose::Meta::TypeConstraint::DuckType::BEGIN@16 which was called: # once (6µs+154µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 16
use Moose::Util 'english_list';
# spent 160µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@16 # spent 154µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
17
18220µs13µs
# spent 3µs within Moose::Meta::TypeConstraint::DuckType::BEGIN@18 which was called: # once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@39 at line 18
use Moose::Util::TypeConstraints ();
# spent 3µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@18
19
202471µs299µs
# spent 52µs (6+47) within Moose::Meta::TypeConstraint::DuckType::BEGIN@20 which was called: # once (6µs+47µs) by Moose::Util::TypeConstraints::BEGIN@39 at line 20
use base 'Moose::Meta::TypeConstraint';
# spent 52µs making 1 call to Moose::Meta::TypeConstraint::DuckType::BEGIN@20 # spent 47µs making 1 call to base::import
21
2213µs3285µs__PACKAGE__->meta->add_attribute('methods' => (
# spent 266µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 14µs making 1 call to Moose::Meta::TypeConstraint::DuckType::meta # spent 5µs making 1 call to Class::MOP::_definition_context
23 accessor => 'methods',
24 Class::MOP::_definition_context(),
25));
26
27my $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 . '}';
3912µs};
40
41sub 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
63sub 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
85sub create_child_type {
86 my ($self, @args) = @_;
87 return Moose::Meta::TypeConstraint->new(@args, parent => $self);
88}
89
90sub 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
10914µs1;
110
111# ABSTRACT: Type constraint for duck typing
112
113__END__