Profile of Moose/Meta/TypeConstraint/Enum.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/Enum.pm
Statements | Executed 20 statements in 690µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 10µs | 33µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@8Moose::Meta::TypeConstraint::Enum::BEGIN@8
1 | 1 | 1 | 10µs | 20µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@4Moose::Meta::TypeConstraint::Enum::BEGIN@4
1 | 1 | 1 | 8µs | 37µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@11Moose::Meta::TypeConstraint::Enum::BEGIN@11
1 | 1 | 1 | 7µs | 187µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@13Moose::Meta::TypeConstraint::Enum::BEGIN@13
1 | 1 | 1 | 7µs | 5.46ms | Moose::Meta::TypeConstraint::Enum::::BEGIN@6Moose::Meta::TypeConstraint::Enum::BEGIN@6
1 | 1 | 1 | 6µs | 10µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@5Moose::Meta::TypeConstraint::Enum::BEGIN@5
1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@9Moose::Meta::TypeConstraint::Enum::BEGIN@9
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::__ANON__[:105]Moose::Meta::TypeConstraint::Enum::__ANON__[:105]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::__ANON__[:32]Moose::Meta::TypeConstraint::Enum::__ANON__[:32]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::__ANON__[:64]Moose::Meta::TypeConstraint::Enum::__ANON__[:64]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::constraintMoose::Meta::TypeConstraint::Enum::constraint
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::create_child_typeMoose::Meta::TypeConstraint::Enum::create_child_type
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::equalsMoose::Meta::TypeConstraint::Enum::equals
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::newMoose::Meta::TypeConstraint::Enum::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::Enum;
2 | 1 | 700ns |  |  | our $VERSION = '2.1604';
3 |  |  |  |  |
4 | 2 | 19µs | 2 | 30µs | # spent 20µs (10+10) within Moose::Meta::TypeConstraint::Enum::BEGIN@4 which was called: # once (10µs+10µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 4 use strict; # spent 20µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@4 # spent 10µs making 1 call to strict::import
5 | 2 | 17µs | 2 | 14µs | # spent 10µs (6+4) within Moose::Meta::TypeConstraint::Enum::BEGIN@5 which was called: # once (6µs+4µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 5 use warnings; # spent 10µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@5 # spent 4µs making 1 call to warnings::import
6 | 2 | 50µs | 2 | 10.9ms | # spent 5.46ms (7µs+5.46) within Moose::Meta::TypeConstraint::Enum::BEGIN@6 which was called: # once (7µs+5.46ms) by Moose::Util::TypeConstraints::BEGIN@30 at line 6 use metaclass; # spent 5.46ms making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@6 # spent 5.46ms making 1 call to metaclass::import
7 |  |  |  |  |
8 | 2 | 26µs | 2 | 55µs | # spent 33µs (10+22) within Moose::Meta::TypeConstraint::Enum::BEGIN@8 which was called: # once (10µs+22µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 8 use B; # spent 33µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@8 # spent 22µs making 1 call to Exporter::import
9 | 2 | 24µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Enum::BEGIN@9 which was called: # once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@30 at line 9 use Moose::Util::TypeConstraints (); # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@9
10 |  |  |  |  |
11 | 2 | 26µs | 2 | 66µs | # spent 37µs (8+29) within Moose::Meta::TypeConstraint::Enum::BEGIN@11 which was called: # once (8µs+29µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 11 use parent 'Moose::Meta::TypeConstraint'; # spent 37µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@11 # spent 29µs making 1 call to parent::import
12 |  |  |  |  |
13 | 2 | 508µs | 2 | 367µs | # spent 187µs (7+180) within Moose::Meta::TypeConstraint::Enum::BEGIN@13 which was called: # once (7µs+180µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 13 use Moose::Util 'throw_exception'; # spent 187µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@13 # spent 180µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
14 |  |  |  |  |
15 | 1 | 7µs | 3 | 408µs | __PACKAGE__->meta->add_attribute('values' => ( # spent 385µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 17µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta # spent 6µs making 1 call to Class::MOP::_definition_context
16 |  |  |  |  | accessor => 'values',
17 |  |  |  |  | Class::MOP::_definition_context(),
18 |  |  |  |  | ));
19 |  |  |  |  |
20 | 1 | 3µs | 3 | 270µs | __PACKAGE__->meta->add_attribute('_inline_var_name' => ( # spent 257µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 9µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta # spent 4µs making 1 call to Class::MOP::_definition_context
21 |  |  |  |  | accessor => '_inline_var_name',
22 |  |  |  |  | Class::MOP::_definition_context(),
23 |  |  |  |  | ));
24 |  |  |  |  |
25 |  |  |  |  | my $inliner = sub {
26 |  |  |  |  | my $self = shift;
27 |  |  |  |  | my $val = shift;
28 |  |  |  |  |
29 |  |  |  |  | return 'defined(' . $val . ') '
30 |  |  |  |  | . '&& !ref(' . $val . ') '
31 |  |  |  |  | . '&& $' . $self->_inline_var_name . '{' . $val . '}';
32 | 1 | 2µs |  |  | };
33 |  |  |  |  |
34 | 1 | 200ns |  |  | my $var_suffix = 0;
35 |  |  |  |  |
36 |  |  |  |  | sub new {
37 |  |  |  |  | my ( $class, %args ) = @_;
38 |  |  |  |  |
39 |  |  |  |  | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Str');
40 |  |  |  |  | $args{inlined} = $inliner;
41 |  |  |  |  |
42 |  |  |  |  | if ( scalar @{ $args{values} } < 1 ) {
43 |  |  |  |  | throw_exception( MustHaveAtLeastOneValueToEnumerate => params => \%args,
44 |  |  |  |  | class => $class
45 |  |  |  |  | );
46 |  |  |  |  | }
47 |  |  |  |  |
48 |  |  |  |  | for (@{ $args{values} }) {
49 |  |  |  |  | if (!defined($_)) {
50 |  |  |  |  | throw_exception( EnumValuesMustBeString => params => \%args,
51 |  |  |  |  | class => $class,
52 |  |  |  |  | value => $_
53 |  |  |  |  | );
54 |  |  |  |  | }
55 |  |  |  |  | elsif (ref($_)) {
56 |  |  |  |  | throw_exception( EnumValuesMustBeString => params => \%args,
57 |  |  |  |  | class => $class,
58 |  |  |  |  | value => $_
59 |  |  |  |  | );
60 |  |  |  |  | }
61 |  |  |  |  | }
62 |  |  |  |  |
63 |  |  |  |  | my %values = map { $_ => 1 } @{ $args{values} };
64 |  |  |  |  | $args{constraint} = sub { $values{ $_[0] } };
65 |  |  |  |  |
66 |  |  |  |  | my $var_name = 'enums' . $var_suffix++;;
67 |  |  |  |  | $args{_inline_var_name} = $var_name;
68 |  |  |  |  | $args{inline_environment} = { '%' . $var_name => \%values };
69 |  |  |  |  |
70 |  |  |  |  | my $self = $class->SUPER::new(\%args);
71 |  |  |  |  |
72 |  |  |  |  | $self->compile_type_constraint()
73 |  |  |  |  | unless $self->_has_compiled_type_constraint;
74 |  |  |  |  |
75 |  |  |  |  | return $self;
76 |  |  |  |  | }
77 |  |  |  |  |
78 |  |  |  |  | sub equals {
79 |  |  |  |  | my ( $self, $type_or_name ) = @_;
80 |  |  |  |  |
81 |  |  |  |  | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
82 |  |  |  |  |
83 |  |  |  |  | return unless $other->isa(__PACKAGE__);
84 |  |  |  |  |
85 |  |  |  |  | my @self_values = sort @{ $self->values };
86 |  |  |  |  | my @other_values = sort @{ $other->values };
87 |  |  |  |  |
88 |  |  |  |  | return unless @self_values == @other_values;
89 |  |  |  |  |
90 |  |  |  |  | while ( @self_values ) {
91 |  |  |  |  | my $value = shift @self_values;
92 |  |  |  |  | my $other_value = shift @other_values;
93 |  |  |  |  |
94 |  |  |  |  | return unless $value eq $other_value;
95 |  |  |  |  | }
96 |  |  |  |  |
97 |  |  |  |  | return 1;
98 |  |  |  |  | }
99 |  |  |  |  |
100 |  |  |  |  | sub constraint {
101 |  |  |  |  | my $self = shift;
102 |  |  |  |  |
103 |  |  |  |  | my %values = map { $_ => undef } @{ $self->values };
104 |  |  |  |  |
105 |  |  |  |  | return sub { exists $values{$_[0]} };
106 |  |  |  |  | }
107 |  |  |  |  |
108 |  |  |  |  | sub create_child_type {
109 |  |  |  |  | my ($self, @args) = @_;
110 |  |  |  |  | return Moose::Meta::TypeConstraint->new(@args, parent => $self);
111 |  |  |  |  | }
112 |  |  |  |  |
113 | 1 | 6µs |  |  | 1;
114 |  |  |  |  |
115 |  |  |  |  | # ABSTRACT: Type constraint for enumerated values.
116 |  |  |  |  |
117 |  |  |  |  | __END__