Filename | /Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/Enum.pm |
Statements | Executed 20 statements in 686µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 15µs | 398µs | BEGIN@11 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 12µs | 12µs | BEGIN@14 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 8µs | 8µs | BEGIN@2 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 7µs | 20µs | BEGIN@13 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 6µs | 25µs | BEGIN@9 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 6µs | 9µs | BEGIN@10 | Moose::Meta::TypeConstraint::Enum::
1 | 1 | 1 | 6µs | 58µs | BEGIN@16 | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | __ANON__[:103] | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | __ANON__[:35] | Moose::Meta::TypeConstraint::Enum::
0 | 0 | 0 | 0s | 0s | __ANON__[:62] | 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 | # spent 8µs within Moose::Meta::TypeConstraint::Enum::BEGIN@2 which was called:
# once (8µs+0s) by Moose::Util::TypeConstraints::BEGIN@38 at line 4 | ||||
3 | 1 | 4µs | $Moose::Meta::TypeConstraint::Enum::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 27µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@2 |
5 | { | ||||
6 | 2 | 800ns | $Moose::Meta::TypeConstraint::Enum::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 20µs | 2 | 45µs | # spent 25µs (6+19) within Moose::Meta::TypeConstraint::Enum::BEGIN@9 which was called:
# once (6µs+19µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 9 # spent 25µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@9
# spent 19µs making 1 call to strict::import |
10 | 2 | 31µs | 2 | 12µs | # spent 9µs (6+3) within Moose::Meta::TypeConstraint::Enum::BEGIN@10 which was called:
# once (6µs+3µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 10 # spent 9µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@10
# spent 3µs making 1 call to warnings::import |
11 | 2 | 25µs | 2 | 781µs | # spent 398µs (15+383) within Moose::Meta::TypeConstraint::Enum::BEGIN@11 which was called:
# once (15µs+383µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 11 # spent 398µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@11
# spent 383µs making 1 call to metaclass::import |
12 | |||||
13 | 2 | 20µs | 2 | 32µs | # spent 20µs (7+13) within Moose::Meta::TypeConstraint::Enum::BEGIN@13 which was called:
# once (7µs+13µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 13 # spent 20µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@13
# spent 13µs making 1 call to Exporter::import |
14 | 2 | 40µs | 1 | 12µs | # spent 12µs within Moose::Meta::TypeConstraint::Enum::BEGIN@14 which was called:
# once (12µs+0s) by Moose::Util::TypeConstraints::BEGIN@38 at line 14 # spent 12µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@14 |
15 | |||||
16 | 2 | 504µs | 2 | 110µs | # spent 58µs (6+52) within Moose::Meta::TypeConstraint::Enum::BEGIN@16 which was called:
# once (6µs+52µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 16 # spent 58µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@16
# spent 52µs making 1 call to base::import |
17 | |||||
18 | 1 | 3µs | 3 | 292µs | __PACKAGE__->meta->add_attribute('values' => ( # spent 274µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 14µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
19 | accessor => 'values', | ||||
20 | Class::MOP::_definition_context(), | ||||
21 | )); | ||||
22 | |||||
23 | 1 | 3µs | 3 | 268µs | __PACKAGE__->meta->add_attribute('_inline_var_name' => ( # spent 255µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 9µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
24 | accessor => '_inline_var_name', | ||||
25 | Class::MOP::_definition_context(), | ||||
26 | )); | ||||
27 | |||||
28 | my $inliner = sub { | ||||
29 | my $self = shift; | ||||
30 | my $val = shift; | ||||
31 | |||||
32 | return 'defined(' . $val . ') ' | ||||
33 | . '&& !ref(' . $val . ') ' | ||||
34 | . '&& $' . $self->_inline_var_name . '{' . $val . '}'; | ||||
35 | 1 | 2µs | }; | ||
36 | |||||
37 | 1 | 100ns | my $var_suffix = 0; | ||
38 | |||||
39 | sub new { | ||||
40 | my ( $class, %args ) = @_; | ||||
41 | |||||
42 | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Str'); | ||||
43 | $args{inlined} = $inliner; | ||||
44 | |||||
45 | if ( scalar @{ $args{values} } < 1 ) { | ||||
46 | require Moose; | ||||
47 | Moose->throw_error("You must have at least one value to enumerate through"); | ||||
48 | } | ||||
49 | |||||
50 | for (@{ $args{values} }) { | ||||
51 | if (!defined($_)) { | ||||
52 | require Moose; | ||||
53 | Moose->throw_error("Enum values must be strings, not undef"); | ||||
54 | } | ||||
55 | elsif (ref($_)) { | ||||
56 | require Moose; | ||||
57 | Moose->throw_error("Enum values must be strings, not '$_'"); | ||||
58 | } | ||||
59 | } | ||||
60 | |||||
61 | my %values = map { $_ => 1 } @{ $args{values} }; | ||||
62 | $args{constraint} = sub { $values{ $_[0] } }; | ||||
63 | |||||
64 | my $var_name = 'enums' . $var_suffix++;; | ||||
65 | $args{_inline_var_name} = $var_name; | ||||
66 | $args{inline_environment} = { '%' . $var_name => \%values }; | ||||
67 | |||||
68 | my $self = $class->SUPER::new(\%args); | ||||
69 | |||||
70 | $self->compile_type_constraint() | ||||
71 | unless $self->_has_compiled_type_constraint; | ||||
72 | |||||
73 | return $self; | ||||
74 | } | ||||
75 | |||||
76 | sub equals { | ||||
77 | my ( $self, $type_or_name ) = @_; | ||||
78 | |||||
79 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
80 | |||||
81 | return unless $other->isa(__PACKAGE__); | ||||
82 | |||||
83 | my @self_values = sort @{ $self->values }; | ||||
84 | my @other_values = sort @{ $other->values }; | ||||
85 | |||||
86 | return unless @self_values == @other_values; | ||||
87 | |||||
88 | while ( @self_values ) { | ||||
89 | my $value = shift @self_values; | ||||
90 | my $other_value = shift @other_values; | ||||
91 | |||||
92 | return unless $value eq $other_value; | ||||
93 | } | ||||
94 | |||||
95 | return 1; | ||||
96 | } | ||||
97 | |||||
98 | sub constraint { | ||||
99 | my $self = shift; | ||||
100 | |||||
101 | my %values = map { $_ => undef } @{ $self->values }; | ||||
102 | |||||
103 | return sub { exists $values{$_[0]} }; | ||||
104 | } | ||||
105 | |||||
106 | sub create_child_type { | ||||
107 | my ($self, @args) = @_; | ||||
108 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
109 | } | ||||
110 | |||||
111 | 1 | 6µs | 1; | ||
112 | |||||
113 | # ABSTRACT: Type constraint for enumerated values. | ||||
114 | |||||
115 | __END__ |