Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeConstraint/Enum.pm |
Statements | Executed 20 statements in 426µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 10µs | 12µs | BEGIN@4 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 7µs | 12µs | BEGIN@5 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 6µs | 148µs | BEGIN@13 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 6µs | 17µs | BEGIN@8 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 4µs | 277µs | BEGIN@6 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 4µs | 22µs | BEGIN@11 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 3µs | 3µs | BEGIN@9 | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | __ANON__[:105] | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | __ANON__[:32] | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | __ANON__[:64] | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | constraint | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | create_child_type | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | equals | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | new | Moose::Meta::TypeConstraint::Enum::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::TypeConstraint::Enum; | ||||
2 | 1 | 300ns | our $VERSION = '2.1605'; | ||
3 | |||||
4 | 2 | 14µs | 2 | 14µs | # spent 12µs (10+2) within Moose::Meta::TypeConstraint::Enum::BEGIN@4 which was called:
# once (10µs+2µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 4 # spent 12µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@4
# spent 2µs making 1 call to strict::import |
5 | 2 | 15µs | 2 | 17µs | # spent 12µs (7+5) within Moose::Meta::TypeConstraint::Enum::BEGIN@5 which was called:
# once (7µs+5µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 5 # spent 12µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@5
# spent 5µs making 1 call to warnings::import |
6 | 2 | 20µs | 2 | 550µs | # spent 277µs (4+273) within Moose::Meta::TypeConstraint::Enum::BEGIN@6 which was called:
# once (4µs+273µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 6 # spent 277µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@6
# spent 273µs making 1 call to metaclass::import |
7 | |||||
8 | 2 | 15µs | 2 | 28µs | # spent 17µs (6+11) within Moose::Meta::TypeConstraint::Enum::BEGIN@8 which was called:
# once (6µs+11µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 8 # spent 17µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@8
# spent 11µs making 1 call to Exporter::import |
9 | 2 | 13µ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 # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@9 |
10 | |||||
11 | 2 | 17µs | 2 | 41µs | # spent 22µs (4+18) within Moose::Meta::TypeConstraint::Enum::BEGIN@11 which was called:
# once (4µs+18µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 11 # spent 22µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@11
# spent 18µs making 1 call to parent::import |
12 | |||||
13 | 2 | 320µs | 2 | 291µs | # spent 148µs (6+143) within Moose::Meta::TypeConstraint::Enum::BEGIN@13 which was called:
# once (6µs+143µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 13 # spent 148µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@13
# spent 143µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
14 | |||||
15 | 1 | 3µs | 3 | 234µs | __PACKAGE__->meta->add_attribute('values' => ( # spent 218µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
16 | accessor => 'values', | ||||
17 | Class::MOP::_definition_context(), | ||||
18 | )); | ||||
19 | |||||
20 | 1 | 2µs | 3 | 187µs | __PACKAGE__->meta->add_attribute('_inline_var_name' => ( # spent 178µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta
# spent 3µ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 | 1µs | }; | ||
33 | |||||
34 | 1 | 100ns | 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 | 4µs | 1; | ||
114 | |||||
115 | # ABSTRACT: Type constraint for enumerated values. | ||||
116 | |||||
117 | __END__ |