Profile of Moose/Meta/TypeConstraint/Class.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:10 2016

Filename | /usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint/Class.pm
Statements | Executed 713 statements in 2.47ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
149 | 1 | 1 | 4.44ms | 5.02ms | Moose::Meta::TypeConstraint::Class::::__ANON__[:25]Moose::Meta::TypeConstraint::Class::__ANON__[:25]
31 | 1 | 1 | 571µs | 22.7ms | Moose::Meta::TypeConstraint::Class::::newMoose::Meta::TypeConstraint::Class::new
1 | 1 | 1 | 11µs | 27µs | Moose::Meta::TypeConstraint::Class::::BEGIN@8Moose::Meta::TypeConstraint::Class::BEGIN@8
1 | 1 | 1 | 10µs | 23µs | Moose::Meta::TypeConstraint::Class::::BEGIN@4Moose::Meta::TypeConstraint::Class::BEGIN@4
1 | 1 | 1 | 6µs | 12µs | Moose::Meta::TypeConstraint::Class::::BEGIN@5Moose::Meta::TypeConstraint::Class::BEGIN@5
1 | 1 | 1 | 6µs | 390µs | Moose::Meta::TypeConstraint::Class::::BEGIN@6Moose::Meta::TypeConstraint::Class::BEGIN@6
1 | 1 | 1 | 6µs | 25µs | Moose::Meta::TypeConstraint::Class::::BEGIN@12Moose::Meta::TypeConstraint::Class::BEGIN@12
1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeConstraint::Class::::BEGIN@10Moose::Meta::TypeConstraint::Class::BEGIN@10
1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeConstraint::Class::::BEGIN@9Moose::Meta::TypeConstraint::Class::BEGIN@9
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::__ANON__[:34]Moose::Meta::TypeConstraint::Class::__ANON__[:34]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::create_child_typeMoose::Meta::TypeConstraint::Class::create_child_type
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::equalsMoose::Meta::TypeConstraint::Class::equals
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::get_messageMoose::Meta::TypeConstraint::Class::get_message
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::is_a_type_ofMoose::Meta::TypeConstraint::Class::is_a_type_of
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::is_subtype_ofMoose::Meta::TypeConstraint::Class::is_subtype_of
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Class::::parentsMoose::Meta::TypeConstraint::Class::parents

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::Class;
2 | 1 | 600ns |  |  | our $VERSION = '2.1604';
3 |  |  |  |  |
4 | 2 | 22µs | 2 | 35µs | # spent 23µs (10+12) within Moose::Meta::TypeConstraint::Class::BEGIN@4 which was called: # once (10µs+12µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 4 use strict; # spent 23µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@4 # spent 12µs making 1 call to strict::import
5 | 2 | 18µs | 2 | 18µs | # spent 12µs (6+6) within Moose::Meta::TypeConstraint::Class::BEGIN@5 which was called: # once (6µs+6µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 5 use warnings; # spent 12µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@5 # spent 6µs making 1 call to warnings::import
6 | 2 | 24µs | 2 | 774µs | # spent 390µs (6+384) within Moose::Meta::TypeConstraint::Class::BEGIN@6 which was called: # once (6µs+384µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 6 use metaclass; # spent 390µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@6 # spent 384µs making 1 call to metaclass::import
7 |  |  |  |  |
8 | 2 | 23µs | 2 | 44µs | # spent 27µs (11+16) within Moose::Meta::TypeConstraint::Class::BEGIN@8 which was called: # once (11µs+16µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 8 use B; # spent 27µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@8 # spent 16µs making 1 call to Exporter::import
9 | 2 | 16µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Class::BEGIN@9 which was called: # once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@28 at line 9 use Scalar::Util (); # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@9
10 | 2 | 19µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Class::BEGIN@10 which was called: # once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@28 at line 10 use Moose::Util::TypeConstraints (); # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@10
11 |  |  |  |  |
12 | 2 | 501µs | 2 | 43µs | # spent 25µs (6+19) within Moose::Meta::TypeConstraint::Class::BEGIN@12 which was called: # once (6µs+19µs) by Moose::Util::TypeConstraints::BEGIN@28 at line 12 use parent 'Moose::Meta::TypeConstraint'; # spent 25µs making 1 call to Moose::Meta::TypeConstraint::Class::BEGIN@12 # spent 19µs making 1 call to parent::import
13 |  |  |  |  |
14 | 1 | 5µs | 3 | 304µs | __PACKAGE__->meta->add_attribute('class' => ( # spent 286µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::Class::meta # spent 4µs making 1 call to Class::MOP::_definition_context
15 |  |  |  |  | reader => 'class',
16 |  |  |  |  | Class::MOP::_definition_context(),
17 |  |  |  |  | ));
18 |  |  |  |  |
19 |  |  |  |  | # spent 5.02ms (4.44+581µs) within Moose::Meta::TypeConstraint::Class::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint/Class.pm:25] which was called 149 times, avg 34µs/call: # 149 times (4.44ms+581µs) by Moose::Meta::TypeConstraint::_inline_check at line 195 of Moose/Meta/TypeConstraint.pm, avg 34µs/call my $inliner = sub {
20 | 149 | 35µs |  |  | my $self = shift;
21 | 149 | 39µs |  |  | my $val = shift;
22 |  |  |  |  |
23 | 149 | 1.26ms | 298 | 581µs | return 'Scalar::Util::blessed(' . $val . ')' # spent 332µs making 149 calls to B::perlstring, avg 2µs/call # spent 249µs making 149 calls to Moose::Meta::TypeConstraint::Class::class, avg 2µs/call
24 |  |  |  |  | . ' && ' . $val . '->isa(' . B::perlstring($self->class) . ')';
25 | 1 | 2µs |  |  | };
26 |  |  |  |  |
27 |  |  |  |  | # spent 22.7ms (571µs+22.1) within Moose::Meta::TypeConstraint::Class::new which was called 31 times, avg 731µs/call: # 31 times (571µs+22.1ms) by Moose::Util::TypeConstraints::create_class_type_constraint at line 176 of Moose/Util/TypeConstraints.pm, avg 731µs/call sub new {
28 | 31 | 40µs |  |  | my ( $class, %args ) = @_;
29 |  |  |  |  |
30 | 31 | 60µs | 31 | 427µs | $args{parent} # spent 427µs making 31 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 14µs/call
31 |  |  |  |  | = Moose::Util::TypeConstraints::find_type_constraint('Object');
32 |  |  |  |  |
33 | 31 | 20µs |  |  | my $class_name = $args{class};
34 | 31 | 114µs |  |  | $args{constraint} = sub { $_[0]->isa($class_name) };
35 |  |  |  |  |
36 | 31 | 26µs |  |  | $args{inlined} = $inliner;
37 |  |  |  |  |
38 | 31 | 103µs | 31 | 16.5ms | my $self = $class->SUPER::new( \%args ); # spent 16.5ms making 31 calls to Moose::Meta::TypeConstraint::new, avg 534µs/call
39 |  |  |  |  |
40 | 31 | 42µs | 31 | 5.11ms | $self->compile_type_constraint(); # spent 5.11ms making 31 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 165µs/call
41 |  |  |  |  |
42 | 31 | 92µs |  |  | return $self;
43 |  |  |  |  | }
44 |  |  |  |  |
45 |  |  |  |  | sub parents {
46 |  |  |  |  | my $self = shift;
47 |  |  |  |  | return (
48 |  |  |  |  | $self->parent,
49 |  |  |  |  | map {
50 |  |  |  |  | # FIXME find_type_constraint might find a TC named after the class but that isn't really it
51 |  |  |  |  | # I did this anyway since it's a convention that preceded TypeConstraint::Class, and it should DWIM
52 |  |  |  |  | # if anybody thinks this problematic please discuss on IRC.
53 |  |  |  |  | # a possible fix is to add by attr indexing to the type registry to find types of a certain property
54 |  |  |  |  | # regardless of their name
55 |  |  |  |  | Moose::Util::TypeConstraints::find_type_constraint($_)
56 |  |  |  |  | ||
57 |  |  |  |  | __PACKAGE__->new( class => $_, name => "__ANON__" )
58 |  |  |  |  | } Class::MOP::class_of($self->class)->superclasses,
59 |  |  |  |  | );
60 |  |  |  |  | }
61 |  |  |  |  |
62 |  |  |  |  | sub equals {
63 |  |  |  |  | my ( $self, $type_or_name ) = @_;
64 |  |  |  |  |
65 |  |  |  |  | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
66 |  |  |  |  |
67 |  |  |  |  | if (!defined($other)) {
68 |  |  |  |  | if (!ref($type_or_name)) {
69 |  |  |  |  | return $self->class eq $type_or_name;
70 |  |  |  |  | }
71 |  |  |  |  | return;
72 |  |  |  |  | }
73 |  |  |  |  |
74 |  |  |  |  | return unless $other->isa(__PACKAGE__);
75 |  |  |  |  |
76 |  |  |  |  | return $self->class eq $other->class;
77 |  |  |  |  | }
78 |  |  |  |  |
79 |  |  |  |  | sub is_a_type_of {
80 |  |  |  |  | my ($self, $type_or_name) = @_;
81 |  |  |  |  |
82 |  |  |  |  | ($self->equals($type_or_name) || $self->is_subtype_of($type_or_name));
83 |  |  |  |  | }
84 |  |  |  |  |
85 |  |  |  |  | sub is_subtype_of {
86 |  |  |  |  | my ($self, $type_or_name_or_class ) = @_;
87 |  |  |  |  |
88 |  |  |  |  | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class);
89 |  |  |  |  |
90 |  |  |  |  | if ( not defined $type ) {
91 |  |  |  |  | if ( not ref $type_or_name_or_class ) {
92 |  |  |  |  | # it might be a class
93 |  |  |  |  | my $class = $self->class;
94 |  |  |  |  | return 1 if $class ne $type_or_name_or_class
95 |  |  |  |  | && $class->isa( $type_or_name_or_class );
96 |  |  |  |  | }
97 |  |  |  |  | return;
98 |  |  |  |  | }
99 |  |  |  |  |
100 |  |  |  |  | if ( $type->isa(__PACKAGE__) && $type->class ne $self->class) {
101 |  |  |  |  | # if $type_or_name_or_class isn't a class, it might be the TC name of another ::Class type
102 |  |  |  |  | # or it could also just be a type object in this branch
103 |  |  |  |  | return $self->class->isa( $type->class );
104 |  |  |  |  | } else {
105 |  |  |  |  | # the only other thing we are a subtype of is Object
106 |  |  |  |  | $self->SUPER::is_subtype_of($type);
107 |  |  |  |  | }
108 |  |  |  |  | }
109 |  |  |  |  |
110 |  |  |  |  | # This is a bit counter-intuitive, but a child type of a Class type
111 |  |  |  |  | # constraint is not itself a Class type constraint (it has no class
112 |  |  |  |  | # attribute). This whole create_child_type thing needs some changing
113 |  |  |  |  | # though, probably making MMC->new a factory or something.
114 |  |  |  |  | sub create_child_type {
115 |  |  |  |  | my ($self, @args) = @_;
116 |  |  |  |  | return Moose::Meta::TypeConstraint->new(@args, parent => $self);
117 |  |  |  |  | }
118 |  |  |  |  |
119 |  |  |  |  | sub get_message {
120 |  |  |  |  | my $self = shift;
121 |  |  |  |  | my ($value) = @_;
122 |  |  |  |  |
123 |  |  |  |  | if ($self->has_message) {
124 |  |  |  |  | return $self->SUPER::get_message(@_);
125 |  |  |  |  | }
126 |  |  |  |  |
127 |  |  |  |  | $value = (defined $value ? overload::StrVal($value) : 'undef');
128 |  |  |  |  | return "Validation failed for '" . $self->name . "' with value $value (not isa " . $self->class . ")";
129 |  |  |  |  | }
130 |  |  |  |  |
131 | 1 | 4µs |  |  | 1;
132 |  |  |  |  |
133 |  |  |  |  | # ABSTRACT: Class/TypeConstraint parallel hierarchy
134 |  |  |  |  |
135 |  |  |  |  | __END__