← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:35 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint/Enum.pm
StatementsExecuted 26 statements in 652µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11110µs33µsMoose::Meta::TypeConstraint::Enum::::BEGIN@13Moose::Meta::TypeConstraint::Enum::BEGIN@13
11110µs10µsMoose::Meta::TypeConstraint::Enum::::BEGIN@2Moose::Meta::TypeConstraint::Enum::BEGIN@2
1119µs14µsMoose::Meta::TypeConstraint::Enum::::BEGIN@9Moose::Meta::TypeConstraint::Enum::BEGIN@9
1118µs25µsMoose::Meta::TypeConstraint::Enum::::BEGIN@10Moose::Meta::TypeConstraint::Enum::BEGIN@10
1118µs80µsMoose::Meta::TypeConstraint::Enum::::BEGIN@16Moose::Meta::TypeConstraint::Enum::BEGIN@16
1117µs559µsMoose::Meta::TypeConstraint::Enum::::BEGIN@11Moose::Meta::TypeConstraint::Enum::BEGIN@11
1114µs4µsMoose::Meta::TypeConstraint::Enum::::BEGIN@14Moose::Meta::TypeConstraint::Enum::BEGIN@14
0000s0sMoose::Meta::TypeConstraint::Enum::::__ANON__[:103]Moose::Meta::TypeConstraint::Enum::__ANON__[:103]
0000s0sMoose::Meta::TypeConstraint::Enum::::__ANON__[:35]Moose::Meta::TypeConstraint::Enum::__ANON__[:35]
0000s0sMoose::Meta::TypeConstraint::Enum::::__ANON__[:62]Moose::Meta::TypeConstraint::Enum::__ANON__[:62]
0000s0sMoose::Meta::TypeConstraint::Enum::::constraintMoose::Meta::TypeConstraint::Enum::constraint
0000s0sMoose::Meta::TypeConstraint::Enum::::create_child_typeMoose::Meta::TypeConstraint::Enum::create_child_type
0000s0sMoose::Meta::TypeConstraint::Enum::::equalsMoose::Meta::TypeConstraint::Enum::equals
0000s0sMoose::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
1package Moose::Meta::TypeConstraint::Enum;
2
# spent 10µs within Moose::Meta::TypeConstraint::Enum::BEGIN@2 which was called: # once (10µs+0s) by Moose::Util::TypeConstraints::BEGIN@38 at line 4
BEGIN {
314µs $Moose::Meta::TypeConstraint::Enum::AUTHORITY = 'cpan:STEVAN';
4124µs110µs}
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@2
5{
621µs $Moose::Meta::TypeConstraint::Enum::VERSION = '2.0602';
7}
8
9319µs219µs
# spent 14µs (9+5) within Moose::Meta::TypeConstraint::Enum::BEGIN@9 which was called: # once (9µs+5µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 9
use strict;
# spent 14µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@9 # spent 5µs making 1 call to strict::import
10321µs242µs
# spent 25µs (8+17) within Moose::Meta::TypeConstraint::Enum::BEGIN@10 which was called: # once (8µs+17µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 10
use warnings;
# spent 25µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@10 # spent 17µs making 1 call to warnings::import
11326µs21.11ms
# spent 559µs (7+552) within Moose::Meta::TypeConstraint::Enum::BEGIN@11 which was called: # once (7µs+552µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 11
use metaclass;
# spent 559µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@11 # spent 552µs making 1 call to metaclass::import
12
13324µs257µs
# spent 33µs (10+23) within Moose::Meta::TypeConstraint::Enum::BEGIN@13 which was called: # once (10µs+23µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 13
use B;
# spent 33µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@13 # spent 23µs making 1 call to Exporter::import
14318µs14µs
# spent 4µs within Moose::Meta::TypeConstraint::Enum::BEGIN@14 which was called: # once (4µs+0s) by Moose::Util::TypeConstraints::BEGIN@38 at line 14
use Moose::Util::TypeConstraints ();
# spent 4µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@14
15
163492µs2152µs
# spent 80µs (8+72) within Moose::Meta::TypeConstraint::Enum::BEGIN@16 which was called: # once (8µs+72µs) by Moose::Util::TypeConstraints::BEGIN@38 at line 16
use base 'Moose::Meta::TypeConstraint';
# spent 80µs making 1 call to Moose::Meta::TypeConstraint::Enum::BEGIN@16 # spent 72µs making 1 call to base::import
17
1816µs3466µs__PACKAGE__->meta->add_attribute('values' => (
# spent 440µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 17µs making 1 call to Moose::Meta::TypeConstraint::Enum::meta # spent 9µs making 1 call to Class::MOP::_definition_context
19 accessor => 'values',
20 Class::MOP::_definition_context(),
21));
22
2314µs3291µs__PACKAGE__->meta->add_attribute('_inline_var_name' => (
# spent 275µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µ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
28my $inliner = sub {
29 my $self = shift;
30 my $val = shift;
31
32 return 'defined(' . $val . ') '
33 . '&& !ref(' . $val . ') '
34 . '&& $' . $self->_inline_var_name . '{' . $val . '}';
3512µs};
36
371300nsmy $var_suffix = 0;
38
39sub 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
76sub 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
98sub constraint {
99 my $self = shift;
100
101 my %values = map { $_ => undef } @{ $self->values };
102
103 return sub { exists $values{$_[0]} };
104}
105
106sub create_child_type {
107 my ($self, @args) = @_;
108 return Moose::Meta::TypeConstraint->new(@args, parent => $self);
109}
110
111110µs1;
112
113# ABSTRACT: Type constraint for enumerated values.
114
- -
117=pod
118
119=head1 NAME
120
121Moose::Meta::TypeConstraint::Enum - Type constraint for enumerated values.
122
123=head1 VERSION
124
125version 2.0602
126
127=head1 DESCRIPTION
128
129This class represents type constraints based on an enumerated list of
130acceptable values.
131
132=head1 INHERITANCE
133
134C<Moose::Meta::TypeConstraint::Enum> is a subclass of
135L<Moose::Meta::TypeConstraint>.
136
137=head1 METHODS
138
139=over 4
140
141=item B<< Moose::Meta::TypeConstraint::Enum->new(%options) >>
142
143This creates a new enum type constraint based on the given
144C<%options>.
145
146It takes the same options as its parent, with several
147exceptions. First, it requires an additional option, C<values>. This
148should be an array reference containing a list of valid string
149values. Second, it automatically sets the parent to the C<Str> type.
150
151Finally, it ignores any provided C<constraint> option. The constraint
152is generated automatically based on the provided C<values>.
153
154=item B<< $constraint->values >>
155
156Returns the array reference of acceptable values provided to the
157constructor.
158
159=item B<< $constraint->create_child_type >>
160
161This returns a new L<Moose::Meta::TypeConstraint> object with the type
162as its parent.
163
164Note that it does I<not> return a C<Moose::Meta::TypeConstraint::Enum>
165object!
166
167=back
168
169=head1 BUGS
170
171See L<Moose/BUGS> for details on reporting bugs.
172
173=head1 AUTHOR
174
175Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
176
177=head1 COPYRIGHT AND LICENSE
178
179This software is copyright (c) 2012 by Infinity Interactive, Inc..
180
181This is free software; you can redistribute it and/or modify it under
182the same terms as the Perl 5 programming language system itself.
183
184=cut
185
186
187__END__