| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint/Enum.pm |
| Statements | Executed 33 statements in 2.53ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 207µs | 1.55ms | Moose::Meta::TypeConstraint::Enum::new |
| 1 | 1 | 1 | 72µs | 90µs | Moose::Meta::TypeConstraint::Enum::BEGIN@3 |
| 1 | 1 | 1 | 65µs | 134µs | Moose::Meta::TypeConstraint::Enum::BEGIN@4 |
| 1 | 1 | 1 | 53µs | 65µs | Moose::Meta::TypeConstraint::Enum::constraint |
| 1 | 1 | 1 | 40µs | 362µs | Moose::Meta::TypeConstraint::Enum::BEGIN@13 |
| 1 | 1 | 1 | 36µs | 3.06ms | Moose::Meta::TypeConstraint::Enum::BEGIN@5 |
| 1 | 1 | 1 | 24µs | 24µs | Moose::Meta::TypeConstraint::Enum::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::__ANON__[:75] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::__ANON__[:83] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::_compile_hand_optimized_type_constraint |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::create_child_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::equals |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::TypeConstraint::Enum; | ||||
| 2 | |||||
| 3 | 3 | 100µs | 2 | 108µs | # spent 90µs (72+18) within Moose::Meta::TypeConstraint::Enum::BEGIN@3 which was called:
# once (72µs+18µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 3 # spent 90µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@3
# spent 18µs making 1 call to strict::import |
| 4 | 3 | 99µs | 2 | 202µs | # spent 134µs (65+68) within Moose::Meta::TypeConstraint::Enum::BEGIN@4 which was called:
# once (65µs+68µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 4 # spent 134µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@4
# spent 68µs making 1 call to warnings::import |
| 5 | 3 | 145µs | 2 | 6.09ms | # spent 3.06ms (36µs+3.03) within Moose::Meta::TypeConstraint::Enum::BEGIN@5 which was called:
# once (36µs+3.03ms) by Moose::Util::TypeConstraints::BEGIN@35 at line 5 # spent 3.06ms making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@5
# spent 3.03ms making 1 call to metaclass::import |
| 6 | |||||
| 7 | 3 | 245µs | 1 | 24µs | # spent 24µs within Moose::Meta::TypeConstraint::Enum::BEGIN@7 which was called:
# once (24µs+0s) by Moose::Util::TypeConstraints::BEGIN@35 at line 7 # spent 24µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@7 |
| 8 | |||||
| 9 | 1 | 6µs | our $VERSION = '1.19'; | ||
| 10 | 1 | 62µs | $VERSION = eval $VERSION; # spent 12µs executing statements in string eval | ||
| 11 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 12 | |||||
| 13 | 3 | 1.55ms | 2 | 685µs | # spent 362µs (40+323) within Moose::Meta::TypeConstraint::Enum::BEGIN@13 which was called:
# once (40µs+323µs) by Moose::Util::TypeConstraints::BEGIN@35 at line 13 # spent 362µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@13
# spent 323µs making 1 call to base::import |
| 14 | |||||
| 15 | 1 | 27µs | 2 | 2.22ms | __PACKAGE__->meta->add_attribute('values' => ( # spent 2.11ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 116µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta |
| 16 | accessor => 'values', | ||||
| 17 | )); | ||||
| 18 | |||||
| 19 | # spent 1.55ms (207µs+1.35) within Moose::Meta::TypeConstraint::Enum::new which was called:
# once (207µs+1.35ms) by Moose::Util::TypeConstraints::create_enum_type_constraint at line 460 of Moose/Util/TypeConstraints.pm | ||||
| 20 | 10 | 186µs | my ( $class, %args ) = @_; | ||
| 21 | |||||
| 22 | 1 | 126µs | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Str'); # spent 126µs making 1 call to Moose::Util::TypeConstraints::find_type_constraint | ||
| 23 | |||||
| 24 | if ( scalar @{ $args{values} } < 2 ) { | ||||
| 25 | require Moose; | ||||
| 26 | Moose->throw_error("You must have at least two values to enumerate through"); | ||||
| 27 | } | ||||
| 28 | |||||
| 29 | for (@{ $args{values} }) { | ||||
| 30 | if (!defined($_)) { | ||||
| 31 | require Moose; | ||||
| 32 | Moose->throw_error("Enum values must be strings, not undef"); | ||||
| 33 | } | ||||
| 34 | elsif (ref($_)) { | ||||
| 35 | require Moose; | ||||
| 36 | Moose->throw_error("Enum values must be strings, not '$_'"); | ||||
| 37 | } | ||||
| 38 | } | ||||
| 39 | |||||
| 40 | 1 | 413µs | my $self = $class->_new(\%args); # spent 413µs making 1 call to Moose::Meta::TypeConstraint::Enum::_new | ||
| 41 | |||||
| 42 | 2 | 808µs | $self->compile_type_constraint() # spent 797µs making 1 call to Moose::Meta::TypeConstraint::compile_type_constraint
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::_has_compiled_type_constraint | ||
| 43 | unless $self->_has_compiled_type_constraint; | ||||
| 44 | |||||
| 45 | return $self; | ||||
| 46 | } | ||||
| 47 | |||||
| 48 | sub equals { | ||||
| 49 | my ( $self, $type_or_name ) = @_; | ||||
| 50 | |||||
| 51 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 52 | |||||
| 53 | return unless $other->isa(__PACKAGE__); | ||||
| 54 | |||||
| 55 | my @self_values = sort @{ $self->values }; | ||||
| 56 | my @other_values = sort @{ $other->values }; | ||||
| 57 | |||||
| 58 | return unless @self_values == @other_values; | ||||
| 59 | |||||
| 60 | while ( @self_values ) { | ||||
| 61 | my $value = shift @self_values; | ||||
| 62 | my $other_value = shift @other_values; | ||||
| 63 | |||||
| 64 | return unless $value eq $other_value; | ||||
| 65 | } | ||||
| 66 | |||||
| 67 | return 1; | ||||
| 68 | } | ||||
| 69 | |||||
| 70 | # spent 65µs (53+12) within Moose::Meta::TypeConstraint::Enum::constraint which was called:
# once (53µs+12µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 213 of Moose/Meta/TypeConstraint.pm | ||||
| 71 | 3 | 76µs | my $self = shift; | ||
| 72 | |||||
| 73 | 1 | 12µs | my %values = map { $_ => undef } @{ $self->values }; # spent 12µs making 1 call to Moose::Meta::TypeConstraint::Enum::values | ||
| 74 | |||||
| 75 | return sub { exists $values{$_[0]} }; | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | sub _compile_hand_optimized_type_constraint { | ||||
| 79 | my $self = shift; | ||||
| 80 | |||||
| 81 | my %values = map { $_ => undef } @{ $self->values }; | ||||
| 82 | |||||
| 83 | sub { defined($_[0]) && !ref($_[0]) && exists $values{$_[0]} }; | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | sub create_child_type { | ||||
| 87 | my ($self, @args) = @_; | ||||
| 88 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | ||||
| 89 | } | ||||
| 90 | |||||
| 91 | 1 | 27µs | 1; | ||
| 92 | |||||
| 93 | __END__ |