← 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:25 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
11114µs16µsMoose::Meta::TypeConstraint::Enum::::BEGIN@3Moose::Meta::TypeConstraint::Enum::BEGIN@3
1118µs47µsMoose::Meta::TypeConstraint::Enum::::BEGIN@13Moose::Meta::TypeConstraint::Enum::BEGIN@13
1117µs16µsMoose::Meta::TypeConstraint::Enum::::BEGIN@4Moose::Meta::TypeConstraint::Enum::BEGIN@4
1115µs102µsMoose::Meta::TypeConstraint::Enum::::BEGIN@5Moose::Meta::TypeConstraint::Enum::BEGIN@5
1113µs3µsMoose::Meta::TypeConstraint::Enum::::BEGIN@7Moose::Meta::TypeConstraint::Enum::BEGIN@7
0000s0sMoose::Meta::TypeConstraint::Enum::::__ANON__[:59]Moose::Meta::TypeConstraint::Enum::__ANON__[:59]
0000s0sMoose::Meta::TypeConstraint::Enum::::__ANON__[:67]Moose::Meta::TypeConstraint::Enum::__ANON__[:67]
0000s0sMoose::Meta::TypeConstraint::Enum::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::Enum::_compile_hand_optimized_type_constraint
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
3326µs219µ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
4318µs225µ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
5323µs2199µ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
7339µs13µ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
91700nsour $VERSION = '0.98';
10114µs$VERSION = eval $VERSION;
111300nsour $AUTHORITY = 'cpan:STEVAN';
12
133280µs286µ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
1513µs2314µ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
19sub 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
32sub 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
54sub constraint {
55 my $self = shift;
56
57 my %values = map { $_ => undef } @{ $self->values };
58
59 return sub { exists $values{$_[0]} };
60}
61
62sub _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
70sub create_child_type {
71 my ($self, @args) = @_;
72 return Moose::Meta::TypeConstraint->new(@args, parent => $self);
73}
74
75114µs1;
76
77__END__
78
79=pod
80
81=head1 NAME
82
83Moose::Meta::TypeConstraint::Enum - Type constraint for enumerated values.
84
85=head1 DESCRIPTION
86
87This class represents type constraints based on an enumerated list of
88acceptable values.
89
90=head1 INHERITANCE
91
92C<Moose::Meta::TypeConstraint::Enum> is a subclass of
93L<Moose::Meta::TypeConstraint>.
94
95=head1 METHODS
96
97=over 4
98
99=item B<< Moose::Meta::TypeConstraint::Enum->new(%options) >>
100
101This creates a new enum type constraint based on the given
102C<%options>.
103
104It takes the same options as its parent, with several
105exceptions. First, it requires an additional option, C<values>. This
106should be an array reference containing a list of valid string
107values. Second, it automatically sets the parent to the C<Str> type.
108
109Finally, it ignores any provided C<constraint> option. The constraint
110is generated automatically based on the provided C<values>.
111
112=item B<< $constraint->values >>
113
114Returns the array reference of acceptable values provided to the
115constructor.
116
117=item B<< $constraint->create_child_type >>
118
119This returns a new L<Moose::Meta::TypeConstraint> object with the type
120as its parent.
121
122Note that it does I<not> return a C<Moose::Meta::TypeConstraint::Enum>
123object!
124
125=back
126
127=head1 BUGS
128
129See L<Moose/BUGS> for details on reporting bugs.
130
131=head1 AUTHOR
132
133Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
134
135=head1 COPYRIGHT AND LICENSE
136
137Copyright 2006-2010 by Infinity Interactive, Inc.
138
139L<http://www.iinteractive.com>
140
141This library is free software; you can redistribute it and/or modify
142it under the same terms as Perl itself.
143
144=cut
145
146