| File | /usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Registry.pm |
| Statements Executed | 362 |
| Total Time | 0.0019228 seconds |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 29 | 6 | 1 | 429µs | 856µs | Moose::Meta::TypeConstraint::Registry::add_type_constraint |
| 56 | 3 | 1 | 379µs | 582µs | Moose::Meta::TypeConstraint::Registry::get_type_constraint |
| 41 | 1 | 1 | 283µs | 481µs | Moose::Meta::TypeConstraint::Registry::has_type_constraint |
| 1 | 1 | 1 | 14µs | 452µs | Moose::Meta::TypeConstraint::Registry::new |
| 1 | 1 | 1 | 7µs | 7µs | Moose::Meta::TypeConstraint::Registry::__ANON__[:24] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Registry::BEGIN |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::Registry::find_type_constraint |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | ||||
| 2 | package Moose::Meta::TypeConstraint::Registry; | |||
| 3 | ||||
| 4 | 3 | 31µs | 10µs | use strict; # spent 12µs making 1 call to strict::import |
| 5 | 3 | 27µs | 9µs | use warnings; # spent 26µs making 1 call to warnings::import |
| 6 | 3 | 50µs | 17µs | use metaclass; # spent 819µs making 1 call to metaclass::import |
| 7 | ||||
| 8 | 3 | 82µs | 27µs | use Scalar::Util 'blessed'; # spent 56µs making 1 call to Exporter::import |
| 9 | ||||
| 10 | 1 | 800ns | 800ns | our $VERSION = '1.15'; |
| 11 | 1 | 23µs | 23µs | $VERSION = eval $VERSION; |
| 12 | 1 | 600ns | 600ns | our $AUTHORITY = 'cpan:STEVAN'; |
| 13 | ||||
| 14 | 3 | 379µs | 126µs | use base 'Class::MOP::Object'; # spent 73µs making 1 call to base::import |
| 15 | ||||
| 16 | 1 | 29µs | 29µs | __PACKAGE__->meta->add_attribute('parent_registry' => ( # spent 1.15ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 44µs making 1 call to Moose::Meta::TypeConstraint::Registry::meta |
| 17 | reader => 'get_parent_registry', | |||
| 18 | writer => 'set_parent_registry', | |||
| 19 | predicate => 'has_parent_registry', | |||
| 20 | )); | |||
| 21 | ||||
| 22 | __PACKAGE__->meta->add_attribute('type_constraints' => ( | |||
| 23 | reader => 'type_constraints', | |||
| 24 | 1 | 2µs | 2µs | # spent 7µs within Moose::Meta::TypeConstraint::Registry::__ANON__[/usr/local/lib/perl/5.10.0/Moose/Meta/TypeConstraint/Registry.pm:24] which was called
# once (7µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of /usr/local/lib/perl/5.10.0/Class/MOP/Mixin/AttributeCore.pm |
| 25 | 1 | 12µs | 12µs | )); # spent 576µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 29µs making 1 call to Moose::Meta::TypeConstraint::Registry::meta |
| 26 | ||||
| 27 | # spent 452µs (14+438) within Moose::Meta::TypeConstraint::Registry::new which was called
# once (14µs+438µs) at line 59 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm | |||
| 28 | 1 | 1µs | 1µs | my $class = shift; |
| 29 | 1 | 11µs | 11µs | my $self = $class->_new(@_); # spent 438µs making 1 call to Class::MOP::Object::_new |
| 30 | 1 | 1µs | 1µs | return $self; |
| 31 | } | |||
| 32 | ||||
| 33 | # spent 481µs (283+198) within Moose::Meta::TypeConstraint::Registry::has_type_constraint which was called 41 times, avg 12µs/call:
# 41 times (283µs+198µs) by Moose::Util::TypeConstraints::find_type_constraint at line 260 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm, avg 12µs/call | |||
| 34 | 41 | 58µs | 1µs | my ($self, $type_name) = @_; |
| 35 | 41 | 229µs | 6µs | ($type_name and exists $self->type_constraints->{$type_name}) ? 1 : 0 # spent 198µs making 41 calls to Moose::Meta::TypeConstraint::Registry::type_constraints, avg 5µs/call |
| 36 | } | |||
| 37 | ||||
| 38 | # spent 582µs (379+203) within Moose::Meta::TypeConstraint::Registry::get_type_constraint which was called 56 times, avg 10µs/call:
# 34 times (226µs+120µs) by Moose::Util::TypeConstraints::find_type_constraint at line 261 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm, avg 10µs/call
# 18 times (121µs+70µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 522 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm, avg 11µs/call
# 4 times (32µs+13µs) at line 850 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm, avg 11µs/call | |||
| 39 | 56 | 70µs | 1µs | my ($self, $type_name) = @_; |
| 40 | 56 | 17µs | 304ns | return unless defined $type_name; |
| 41 | 56 | 251µs | 4µs | $self->type_constraints->{$type_name} # spent 203µs making 56 calls to Moose::Meta::TypeConstraint::Registry::type_constraints, avg 4µs/call |
| 42 | } | |||
| 43 | ||||
| 44 | # spent 856µs (429+427) within Moose::Meta::TypeConstraint::Registry::add_type_constraint which was called 29 times, avg 30µs/call:
# 18 times (249µs+263µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 560 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm, avg 28µs/call
# 7 times (104µs+111µs) by Moose::Util::TypeConstraints::register_type_constraint at line 269 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm, avg 31µs/call
# once (31µs+14µs) at line 788 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm
# once (15µs+13µs) at line 830 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm
# once (15µs+13µs) at line 809 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm
# once (15µs+13µs) at line 847 of /usr/local/lib/perl/5.10.0/Moose/Util/TypeConstraints.pm | |||
| 45 | 29 | 31µs | 1µs | my ($self, $type) = @_; |
| 46 | ||||
| 47 | 29 | 302µs | 10µs | unless ( $type && blessed $type && $type->isa('Moose::Meta::TypeConstraint') ) { # spent 109µs making 29 calls to UNIVERSAL::isa, avg 4µs/call
# spent 87µs making 29 calls to Scalar::Util::blessed, avg 3µs/call |
| 48 | require Moose; | |||
| 49 | Moose->throw_error("No type supplied / type is not a valid type constraint"); | |||
| 50 | } | |||
| 51 | ||||
| 52 | 29 | 302µs | 10µs | $self->type_constraints->{$type->name} = $type; # spent 124µs making 29 calls to Moose::Meta::TypeConstraint::name, avg 4µs/call
# spent 108µs making 29 calls to Moose::Meta::TypeConstraint::Registry::type_constraints, avg 4µs/call |
| 53 | } | |||
| 54 | ||||
| 55 | sub find_type_constraint { | |||
| 56 | my ($self, $type_name) = @_; | |||
| 57 | return $self->get_type_constraint($type_name) | |||
| 58 | if $self->has_type_constraint($type_name); | |||
| 59 | return $self->get_parent_registry->find_type_constraint($type_name) | |||
| 60 | if $self->has_parent_registry; | |||
| 61 | return; | |||
| 62 | } | |||
| 63 | ||||
| 64 | 1 | 14µs | 14µs | 1; |
| 65 | ||||
| 66 | __END__ | |||
| 67 | ||||
| 68 | ||||
| 69 | =pod | |||
| 70 | ||||
| 71 | =head1 NAME | |||
| 72 | ||||
| 73 | Moose::Meta::TypeConstraint::Registry - registry for type constraints | |||
| 74 | ||||
| 75 | =head1 DESCRIPTION | |||
| 76 | ||||
| 77 | This class is a registry that maps type constraint names to | |||
| 78 | L<Moose::Meta::TypeConstraint> objects. | |||
| 79 | ||||
| 80 | Currently, it is only used internally by | |||
| 81 | L<Moose::Util::TypeConstraints>, which creates a single global | |||
| 82 | registry. | |||
| 83 | ||||
| 84 | =head1 INHERITANCE | |||
| 85 | ||||
| 86 | C<Moose::Meta::TypeConstraint::Registry> is a subclass of | |||
| 87 | L<Class::MOP::Object>. | |||
| 88 | ||||
| 89 | =head1 METHODS | |||
| 90 | ||||
| 91 | =over 4 | |||
| 92 | ||||
| 93 | =item B<< Moose::Meta::TypeConstraint::Registry->new(%options) >> | |||
| 94 | ||||
| 95 | This creates a new registry object based on the provided C<%options>: | |||
| 96 | ||||
| 97 | =over 8 | |||
| 98 | ||||
| 99 | =item * parent_registry | |||
| 100 | ||||
| 101 | This is an optional L<Moose::Meta::TypeConstraint::Registry> | |||
| 102 | object. | |||
| 103 | ||||
| 104 | =item * type_constraints | |||
| 105 | ||||
| 106 | This is hash reference of type names to type objects. This is | |||
| 107 | optional. Constraints can be added to the registry after it is | |||
| 108 | created. | |||
| 109 | ||||
| 110 | =back | |||
| 111 | ||||
| 112 | =item B<< $registry->get_parent_registry >> | |||
| 113 | ||||
| 114 | Returns the registry's parent registry, if it has one. | |||
| 115 | ||||
| 116 | =item B<< $registry->has_parent_registry >> | |||
| 117 | ||||
| 118 | Returns true if the registry has a parent. | |||
| 119 | ||||
| 120 | =item B<< $registry->set_parent_registry($registry) >> | |||
| 121 | ||||
| 122 | Sets the parent registry. | |||
| 123 | ||||
| 124 | =item B<< $registry->get_type_constraint($type_name) >> | |||
| 125 | ||||
| 126 | This returns the L<Moose::Meta::TypeConstraint> object from the | |||
| 127 | registry for the given name, if one exists. | |||
| 128 | ||||
| 129 | =item B<< $registry->has_type_constraint($type_name) >> | |||
| 130 | ||||
| 131 | Returns true if the registry has a type of the given name. | |||
| 132 | ||||
| 133 | =item B<< $registry->add_type_constraint($type) >> | |||
| 134 | ||||
| 135 | Adds a new L<Moose::Meta::TypeConstraint> object to the registry. | |||
| 136 | ||||
| 137 | =item B<< $registry->find_type_constraint($type_name) >> | |||
| 138 | ||||
| 139 | This method looks in the current registry for the named type. If the | |||
| 140 | type is not found, then this method will look in the registry's | |||
| 141 | parent, if it has one. | |||
| 142 | ||||
| 143 | =back | |||
| 144 | ||||
| 145 | =head1 BUGS | |||
| 146 | ||||
| 147 | See L<Moose/BUGS> for details on reporting bugs. | |||
| 148 | ||||
| 149 | =head1 AUTHOR | |||
| 150 | ||||
| 151 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | |||
| 152 | ||||
| 153 | =head1 COPYRIGHT AND LICENSE | |||
| 154 | ||||
| 155 | Copyright 2006-2010 by Infinity Interactive, Inc. | |||
| 156 | ||||
| 157 | L<http://www.iinteractive.com> | |||
| 158 | ||||
| 159 | This library is free software; you can redistribute it and/or modify | |||
| 160 | it under the same terms as Perl itself. | |||
| 161 | ||||
| 162 | =cut |