← Index
Performance Profile   « block view • line view • sub view »
For t/test-parsing
  Run on Sun Nov 14 09:49:57 2010
Reported on Sun Nov 14 09:50:12 2010

File /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Parameterized.pm
Statements Executed 26
Total Time 0.0007482 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sMoose::Meta::TypeConstraint::Parameterized::::BEGINMoose::Meta::TypeConstraint::Parameterized::BEGIN
0000s0sMoose::Meta::TypeConstraint::Parameterized::::compile_type_constraintMoose::Meta::TypeConstraint::Parameterized::compile_type_constraint
0000s0sMoose::Meta::TypeConstraint::Parameterized::::create_child_typeMoose::Meta::TypeConstraint::Parameterized::create_child_type
0000s0sMoose::Meta::TypeConstraint::Parameterized::::equalsMoose::Meta::TypeConstraint::Parameterized::equals
LineStmts.Exclusive
Time
Avg.Code
1package Moose::Meta::TypeConstraint::Parameterized;
2
3326µs9µsuse strict;
# spent 8µs making 1 call to strict::import
4332µs11µsuse warnings;
# spent 26µs making 1 call to warnings::import
5348µs16µsuse metaclass;
# spent 859µs making 1 call to metaclass::import
6
7331µs10µsuse Scalar::Util 'blessed';
# spent 47µs making 1 call to Exporter::import
8333µs11µsuse Moose::Util::TypeConstraints;
# spent 4µs making 1 call to import
93177µs59µsuse Moose::Meta::TypeConstraint::Parameterizable;
# spent 4µs making 1 call to import
10
111800ns800nsour $VERSION = '1.15';
12124µs24µs$VERSION = eval $VERSION;
131600ns600nsour $AUTHORITY = 'cpan:STEVAN';
14
153344µs115µsuse base 'Moose::Meta::TypeConstraint';
# spent 88µs making 1 call to base::import
16
17117µs17µs__PACKAGE__->meta->add_attribute('type_parameter' => (
# spent 904µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 36µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::meta
18 accessor => 'type_parameter',
19 predicate => 'has_type_parameter',
20));
21
22sub equals {
23 my ( $self, $type_or_name ) = @_;
24
25 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
26
27 return unless $other->isa(__PACKAGE__);
28
29 return (
30 $self->type_parameter->equals( $other->type_parameter )
31 and
32 $self->parent->equals( $other->parent )
33 );
34}
35
36sub compile_type_constraint {
37 my $self = shift;
38
39 unless ( $self->has_type_parameter ) {
40 require Moose;
41 Moose->throw_error("You cannot create a Higher Order type without a type parameter");
42 }
43
44 my $type_parameter = $self->type_parameter;
45
46 unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) {
47 require Moose;
48 Moose->throw_error("The type parameter must be a Moose meta type");
49 }
50
51 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
52 if (my $constraint = $type->generate_constraint_for($self)) {
53 $self->_set_constraint($constraint);
54 return $self->SUPER::compile_type_constraint;
55 }
56 }
57
58 # if we get here, then we couldn't
59 # find a way to parameterize this type
60 require Moose;
61 Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
62 . $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
63}
64
65sub create_child_type {
66 my ($self, %opts) = @_;
67 return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self);
68}
69
70114µs14µs1;
71
72__END__
73
74
75=pod
76
77=head1 NAME
78
79Moose::Meta::TypeConstraint::Parameterized - Type constraints with a bound parameter (ArrayRef[Int])
80
81=head1 METHODS
82
83This class is intentionally not documented because the API is
84confusing and needs some work.
85
86=head1 INHERITANCE
87
88C<Moose::Meta::TypeConstraint::Parameterized> is a subclass of
89L<Moose::Meta::TypeConstraint>.
90
91=head1 BUGS
92
93See L<Moose/BUGS> for details on reporting bugs.
94
95=head1 AUTHOR
96
97Stevan Little E<lt>stevan@iinteractive.comE<gt>
98
99=head1 COPYRIGHT AND LICENSE
100
101Copyright 2006-2010 by Infinity Interactive, Inc.
102
103L<http://www.iinteractive.com>
104
105This library is free software; you can redistribute it and/or modify
106it under the same terms as Perl itself.
107
108=cut