Profile of /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/Enum.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For 05.Domain_and_Item.t
Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:22:20 2010

File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeConstraint/Enum.pm
Statements Executed | 20
Statement Execution Time | 417µs

Subroutines — ordered by exclusive time
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 14µs | 16µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@3Moose::Meta::TypeConstraint::Enum::BEGIN@3
1 | 1 | 1 | 8µs | 47µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@13Moose::Meta::TypeConstraint::Enum::BEGIN@13
1 | 1 | 1 | 7µs | 16µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@4Moose::Meta::TypeConstraint::Enum::BEGIN@4
1 | 1 | 1 | 5µs | 102µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@5Moose::Meta::TypeConstraint::Enum::BEGIN@5
1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeConstraint::Enum::::BEGIN@7Moose::Meta::TypeConstraint::Enum::BEGIN@7
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::__ANON__[:59]Moose::Meta::TypeConstraint::Enum::__ANON__[:59]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::__ANON__[:67]Moose::Meta::TypeConstraint::Enum::__ANON__[:67]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Enum::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::Enum::_compile_hand_optimized_type_constraint
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 |  |  |  |  |
3 | 3 | 26µs | 2 | 19µs | # spent 16µs (14+3) within Moose::Meta::TypeConstraint::Enum::BEGIN@3 which was called # once (14µs+3µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 3 use strict; # spent 16µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@3 # spent 3µs making 1 call to strict::import
4 | 3 | 18µs | 2 | 25µs | # spent 16µs (7+9) within Moose::Meta::TypeConstraint::Enum::BEGIN@4 which was called # once (7µs+9µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 4 use warnings; # spent 16µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@4 # spent 9µs making 1 call to warnings::import
5 | 3 | 23µs | 2 | 199µs | # spent 102µs (5+97) within Moose::Meta::TypeConstraint::Enum::BEGIN@5 which was called # once (5µs+97µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 5 use metaclass; # spent 102µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@5 # spent 97µs making 1 call to metaclass::import
6 |  |  |  |  |
7 | 3 | 39µs | 1 | 3µs | # spent 3µs within Moose::Meta::TypeConstraint::Enum::BEGIN@7 which was called # once (3µs+0s) by Moose::Util::TypeConstraints::BEGIN@34 at line 7 use Moose::Util::TypeConstraints (); # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@7
8 |  |  |  |  |
9 | 1 | 700ns |  |  | our $VERSION = '0.98';
10 | 1 | 14µs |  |  | $VERSION = eval $VERSION;
11 | 1 | 300ns |  |  | our $AUTHORITY = 'cpan:STEVAN';
12 |  |  |  |  |
13 | 3 | 280µs | 2 | 86µs | # spent 47µs (8+39) within Moose::Meta::TypeConstraint::Enum::BEGIN@13 which was called # once (8µs+39µs) by Moose::Util::TypeConstraints::BEGIN@34 at line 13 use base 'Moose::Meta::TypeConstraint'; # spent 47µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@13 # spent 39µs making 1 call to base::import
14 |  |  |  |  |
15 | 1 | 3µs | 2 | 314µs | __PACKAGE__->meta->add_attribute('values' => ( # spent 298µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 16µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta
16 |  |  |  |  | accessor => 'values',
17 |  |  |  |  | ));
18 |  |  |  |  |
19 |  |  |  |  | sub new {
20 |  |  |  |  | my ( $class, %args ) = @_;
21 |  |  |  |  |
22 |  |  |  |  | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Str');
23 |  |  |  |  |
24 |  |  |  |  | my $self = $class->_new(\%args);
25 |  |  |  |  |
26 |  |  |  |  | $self->compile_type_constraint()
27 |  |  |  |  | unless $self->_has_compiled_type_constraint;
28 |  |  |  |  |
29 |  |  |  |  | return $self;
30 |  |  |  |  | }
31 |  |  |  |  |
32 |  |  |  |  | sub equals {
33 |  |  |  |  | my ( $self, $type_or_name ) = @_;
34 |  |  |  |  |
35 |  |  |  |  | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
36 |  |  |  |  |
37 |  |  |  |  | return unless $other->isa(__PACKAGE__);
38 |  |  |  |  |
39 |  |  |  |  | my @self_values = sort @{ $self->values };
40 |  |  |  |  | my @other_values = sort @{ $other->values };
41 |  |  |  |  |
42 |  |  |  |  | return unless @self_values == @other_values;
43 |  |  |  |  |
44 |  |  |  |  | while ( @self_values ) {
45 |  |  |  |  | my $value = shift @self_values;
46 |  |  |  |  | my $other_value = shift @other_values;
47 |  |  |  |  |
48 |  |  |  |  | return unless $value eq $other_value;
49 |  |  |  |  | }
50 |  |  |  |  |
51 |  |  |  |  | return 1;
52 |  |  |  |  | }
53 |  |  |  |  |
54 |  |  |  |  | sub constraint {
55 |  |  |  |  | my $self = shift;
56 |  |  |  |  |
57 |  |  |  |  | my %values = map { $_ => undef } @{ $self->values };
58 |  |  |  |  |
59 |  |  |  |  | return sub { exists $values{$_[0]} };
60 |  |  |  |  | }
61 |  |  |  |  |
62 |  |  |  |  | sub _compile_hand_optimized_type_constraint {
63 |  |  |  |  | my $self = shift;
64 |  |  |  |  |
65 |  |  |  |  | my %values = map { $_ => undef } @{ $self->values };
66 |  |  |  |  |
67 |  |  |  |  | sub { defined($_[0]) && !ref($_[0]) && exists $values{$_[0]} };
68 |  |  |  |  | }
69 |  |  |  |  |
70 |  |  |  |  | sub create_child_type {
71 |  |  |  |  | my ($self, @args) = @_;
72 |  |  |  |  | return Moose::Meta::TypeConstraint->new(@args, parent => $self);
73 |  |  |  |  | }
74 |  |  |  |  |
75 | 1 | 14µs |  |  | 1;
76 |  |  |  |  |
77 |  |  |  |  | __END__
78 |  |  |  |  |
79 |  |  |  |  | =pod
80 |  |  |  |  |
81 |  |  |  |  | =head1 NAME
82 |  |  |  |  |
83 |  |  |  |  | Moose::Meta::TypeConstraint::Enum - Type constraint for enumerated values.
84 |  |  |  |  |
85 |  |  |  |  | =head1 DESCRIPTION
86 |  |  |  |  |
87 |  |  |  |  | This class represents type constraints based on an enumerated list of
88 |  |  |  |  | acceptable values.
89 |  |  |  |  |
90 |  |  |  |  | =head1 INHERITANCE
91 |  |  |  |  |
92 |  |  |  |  | C<Moose::Meta::TypeConstraint::Enum> is a subclass of
93 |  |  |  |  | L<Moose::Meta::TypeConstraint>.
94 |  |  |  |  |
95 |  |  |  |  | =head1 METHODS
96 |  |  |  |  |
97 |  |  |  |  | =over 4
98 |  |  |  |  |
99 |  |  |  |  | =item B<< Moose::Meta::TypeConstraint::Enum->new(%options) >>
100 |  |  |  |  |
101 |  |  |  |  | This creates a new enum type constraint based on the given
102 |  |  |  |  | C<%options>.
103 |  |  |  |  |
104 |  |  |  |  | It takes the same options as its parent, with several
105 |  |  |  |  | exceptions. First, it requires an additional option, C<values>. This
106 |  |  |  |  | should be an array reference containing a list of valid string
107 |  |  |  |  | values. Second, it automatically sets the parent to the C<Str> type.
108 |  |  |  |  |
109 |  |  |  |  | Finally, it ignores any provided C<constraint> option. The constraint
110 |  |  |  |  | is generated automatically based on the provided C<values>.
111 |  |  |  |  |
112 |  |  |  |  | =item B<< $constraint->values >>
113 |  |  |  |  |
114 |  |  |  |  | Returns the array reference of acceptable values provided to the
115 |  |  |  |  | constructor.
116 |  |  |  |  |
117 |  |  |  |  | =item B<< $constraint->create_child_type >>
118 |  |  |  |  |
119 |  |  |  |  | This returns a new L<Moose::Meta::TypeConstraint> object with the type
120 |  |  |  |  | as its parent.
121 |  |  |  |  |
122 |  |  |  |  | Note that it does I<not> return a C<Moose::Meta::TypeConstraint::Enum>
123 |  |  |  |  | object!
124 |  |  |  |  |
125 |  |  |  |  | =back
126 |  |  |  |  |
127 |  |  |  |  | =head1 BUGS
128 |  |  |  |  |
129 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
130 |  |  |  |  |
131 |  |  |  |  | =head1 AUTHOR
132 |  |  |  |  |
133 |  |  |  |  | Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
134 |  |  |  |  |
135 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
136 |  |  |  |  |
137 |  |  |  |  | Copyright 2006-2010 by Infinity Interactive, Inc.
138 |  |  |  |  |
139 |  |  |  |  | L<http://www.iinteractive.com>
140 |  |  |  |  |
141 |  |  |  |  | This library is free software; you can redistribute it and/or modify
142 |  |  |  |  | it under the same terms as Perl itself.
143 |  |  |  |  |
144 |  |  |  |  | =cut
145 |  |  |  |  |
146 |  |  |  |  |