File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeCoercion/Union.pm |
Statements Executed | 23 |
Statement Execution Time | 320µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 37µs | 47µs | compile_type_coercion | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 14µs | 16µs | BEGIN@4 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 7µs | 31µs | BEGIN@8 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 7µs | 15µs | BEGIN@5 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 7µs | 79µs | BEGIN@14 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 6µs | 102µs | BEGIN@6 | Moose::Meta::TypeCoercion::Union::
0 | 0 | 0 | 0s | 0s | __ANON__[:40] | Moose::Meta::TypeCoercion::Union::
0 | 0 | 0 | 0s | 0s | add_type_coercions | Moose::Meta::TypeCoercion::Union::
0 | 0 | 0 | 0s | 0s | has_coercion_for_type | Moose::Meta::TypeCoercion::Union::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Moose::Meta::TypeCoercion::Union; | ||||
3 | |||||
4 | 3 | 21µs | 2 | 19µs | # spent 16µs (14+3) within Moose::Meta::TypeCoercion::Union::BEGIN@4 which was called
# once (14µs+3µs) by Moose::Meta::TypeConstraint::Union::BEGIN@8 at line 4 # spent 16µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@4
# spent 3µs making 1 call to strict::import |
5 | 3 | 18µs | 2 | 24µs | # spent 15µs (7+8) within Moose::Meta::TypeCoercion::Union::BEGIN@5 which was called
# once (7µs+8µs) by Moose::Meta::TypeConstraint::Union::BEGIN@8 at line 5 # spent 15µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@5
# spent 8µs making 1 call to warnings::import |
6 | 3 | 30µs | 2 | 198µs | # spent 102µs (6+96) within Moose::Meta::TypeCoercion::Union::BEGIN@6 which was called
# once (6µs+96µs) by Moose::Meta::TypeConstraint::Union::BEGIN@8 at line 6 # spent 102µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@6
# spent 96µs making 1 call to metaclass::import |
7 | |||||
8 | 3 | 42µs | 2 | 55µs | # spent 31µs (7+24) within Moose::Meta::TypeCoercion::Union::BEGIN@8 which was called
# once (7µs+24µs) by Moose::Meta::TypeConstraint::Union::BEGIN@8 at line 8 # spent 31µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@8
# spent 24µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 700ns | our $VERSION = '0.98'; | ||
11 | 1 | 13µs | $VERSION = eval $VERSION; | ||
12 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
13 | |||||
14 | 3 | 158µs | 2 | 152µs | # spent 79µs (7+73) within Moose::Meta::TypeCoercion::Union::BEGIN@14 which was called
# once (7µs+73µs) by Moose::Meta::TypeConstraint::Union::BEGIN@8 at line 14 # spent 79µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@14
# spent 73µs making 1 call to base::import |
15 | |||||
16 | # spent 47µs (37+10) within Moose::Meta::TypeCoercion::Union::compile_type_coercion which was called
# once (37µs+10µs) by Moose::Meta::TypeCoercion::new at line 35 of Moose/Meta/TypeCoercion.pm | ||||
17 | 1 | 700ns | my $self = shift; | ||
18 | 1 | 6µs | 1 | 4µs | my $type_constraint = $self->type_constraint; # spent 4µs making 1 call to Moose::Meta::TypeCoercion::type_constraint |
19 | |||||
20 | 1 | 14µs | 2 | 3µs | (blessed $type_constraint && $type_constraint->isa('Moose::Meta::TypeConstraint::Union')) # spent 2µs making 1 call to Scalar::Util::blessed
# spent 900ns making 1 call to UNIVERSAL::isa |
21 | || Moose->throw_error("You can only a Moose::Meta::TypeCoercion::Union for a " . | ||||
22 | "Moose::Meta::TypeConstraint::Union, not a $type_constraint"); | ||||
23 | |||||
24 | $self->_compiled_type_coercion(sub { | ||||
25 | my $value = shift; | ||||
26 | # go through all the type constraints | ||||
27 | # in the union, and check em ... | ||||
28 | foreach my $type (@{$type_constraint->type_constraints}) { | ||||
29 | # if they have a coercion first | ||||
30 | if ($type->has_coercion) { | ||||
31 | # then try to coerce them ... | ||||
32 | my $temp = $type->coerce($value); | ||||
33 | # and if they get something | ||||
34 | # make sure it still fits within | ||||
35 | # the union type ... | ||||
36 | return $temp if $type_constraint->check($temp); | ||||
37 | } | ||||
38 | } | ||||
39 | return undef; | ||||
40 | 1 | 13µs | 1 | 4µs | }); # spent 4µs making 1 call to Moose::Meta::TypeCoercion::_compiled_type_coercion |
41 | } | ||||
42 | |||||
43 | sub has_coercion_for_type { 0 } | ||||
44 | |||||
45 | sub add_type_coercions { | ||||
46 | require Moose; | ||||
47 | Moose->throw_error("Cannot add additional type coercions to Union types"); | ||||
48 | } | ||||
49 | |||||
50 | 1 | 4µs | 1; | ||
51 | |||||
52 | __END__ | ||||
53 | |||||
54 | =pod | ||||
55 | |||||
56 | =head1 NAME | ||||
57 | |||||
58 | Moose::Meta::TypeCoercion::Union - The Moose Type Coercion metaclass for Unions | ||||
59 | |||||
60 | =head1 DESCRIPTION | ||||
61 | |||||
62 | This is a subclass of L<Moose::Meta::TypeCoercion> that is used for | ||||
63 | L<Moose::Meta::TypeConstraint::Union> objects. | ||||
64 | =head1 METHODS | ||||
65 | |||||
66 | =over 4 | ||||
67 | |||||
68 | =item B<< $coercion->has_coercion_for_type >> | ||||
69 | |||||
70 | This method always returns false. | ||||
71 | |||||
72 | =item B<< $coercion->add_type_coercions >> | ||||
73 | |||||
74 | This method always throws an error. You cannot add coercions to a | ||||
75 | union type coercion. | ||||
76 | |||||
77 | =item B<< $coercion->coerce($value) >> | ||||
78 | |||||
79 | This method will coerce by trying the coercions for each type in the | ||||
80 | union. | ||||
81 | |||||
82 | =back | ||||
83 | |||||
84 | =head1 BUGS | ||||
85 | |||||
86 | See L<Moose/BUGS> for details on reporting bugs. | ||||
87 | |||||
88 | =head1 AUTHOR | ||||
89 | |||||
90 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
91 | |||||
92 | =head1 COPYRIGHT AND LICENSE | ||||
93 | |||||
94 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
95 | |||||
96 | L<http://www.iinteractive.com> | ||||
97 | |||||
98 | This library is free software; you can redistribute it and/or modify | ||||
99 | it under the same terms as Perl itself. | ||||
100 | |||||
101 | =cut |