Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeCoercion/Union.pm |
Statements | Executed 19 statements in 318µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 59µs | 129µs | BEGIN@16 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 25µs | 37µs | BEGIN@11 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 10µs | 457µs | BEGIN@12 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 9µs | 9µs | BEGIN@3 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 8µs | 11µs | BEGIN@10 | Moose::Meta::TypeCoercion::Union::
1 | 1 | 1 | 7µs | 41µs | BEGIN@14 | Moose::Meta::TypeCoercion::Union::
0 | 0 | 0 | 0s | 0s | __ANON__[:37] | Moose::Meta::TypeCoercion::Union::
0 | 0 | 0 | 0s | 0s | add_type_coercions | Moose::Meta::TypeCoercion::Union::
0 | 0 | 0 | 0s | 0s | compile_type_coercion | 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 | # spent 9µs within Moose::Meta::TypeCoercion::Union::BEGIN@3 which was called:
# once (9µs+0s) by Moose::Meta::TypeConstraint::Union::BEGIN@14 at line 5 | ||||
4 | 1 | 4µs | $Moose::Meta::TypeCoercion::Union::AUTHORITY = 'cpan:STEVAN'; | ||
5 | 1 | 23µs | 1 | 9µs | } # spent 9µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@3 |
6 | { | ||||
7 | 2 | 1µs | $Moose::Meta::TypeCoercion::Union::VERSION = '2.0602'; | ||
8 | } | ||||
9 | |||||
10 | 3 | 18µs | 2 | 14µs | # spent 11µs (8+3) within Moose::Meta::TypeCoercion::Union::BEGIN@10 which was called:
# once (8µs+3µs) by Moose::Meta::TypeConstraint::Union::BEGIN@14 at line 10 # spent 11µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@10
# spent 3µs making 1 call to strict::import |
11 | 3 | 18µs | 2 | 48µs | # spent 37µs (25+11) within Moose::Meta::TypeCoercion::Union::BEGIN@11 which was called:
# once (25µs+11µs) by Moose::Meta::TypeConstraint::Union::BEGIN@14 at line 11 # spent 37µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@11
# spent 12µs making 1 call to warnings::import |
12 | 3 | 26µs | 2 | 903µs | # spent 457µs (10+447) within Moose::Meta::TypeCoercion::Union::BEGIN@12 which was called:
# once (10µs+447µs) by Moose::Meta::TypeConstraint::Union::BEGIN@14 at line 12 # spent 457µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@12
# spent 447µs making 1 call to metaclass::import |
13 | |||||
14 | 3 | 19µs | 2 | 75µs | # spent 41µs (7+34) within Moose::Meta::TypeCoercion::Union::BEGIN@14 which was called:
# once (7µs+34µs) by Moose::Meta::TypeConstraint::Union::BEGIN@14 at line 14 # spent 41µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@14
# spent 34µs making 1 call to Exporter::import |
15 | |||||
16 | 3 | 206µs | 2 | 198µs | # spent 129µs (59+70) within Moose::Meta::TypeCoercion::Union::BEGIN@16 which was called:
# once (59µs+70µs) by Moose::Meta::TypeConstraint::Union::BEGIN@14 at line 16 # spent 129µs making 1 call to Moose::Meta::TypeCoercion::Union::BEGIN@16
# spent 70µs making 1 call to base::import |
17 | |||||
18 | sub compile_type_coercion { | ||||
19 | my $self = shift; | ||||
20 | my $type_constraint = $self->type_constraint; | ||||
21 | |||||
22 | (blessed $type_constraint && $type_constraint->isa('Moose::Meta::TypeConstraint::Union')) | ||||
23 | || Moose->throw_error("You can only create a Moose::Meta::TypeCoercion::Union for a " . | ||||
24 | "Moose::Meta::TypeConstraint::Union, not a $type_constraint"); | ||||
25 | |||||
26 | $self->_compiled_type_coercion( | ||||
27 | sub { | ||||
28 | my $value = shift; | ||||
29 | |||||
30 | foreach my $type ( grep { $_->has_coercion } | ||||
31 | @{ $type_constraint->type_constraints } ) { | ||||
32 | my $temp = $type->coerce($value); | ||||
33 | return $temp if $type_constraint->check($temp); | ||||
34 | } | ||||
35 | |||||
36 | return $value; | ||||
37 | } | ||||
38 | ); | ||||
39 | } | ||||
40 | |||||
41 | sub has_coercion_for_type { 0 } | ||||
42 | |||||
43 | sub add_type_coercions { | ||||
44 | require Moose; | ||||
45 | Moose->throw_error("Cannot add additional type coercions to Union types"); | ||||
46 | } | ||||
47 | |||||
48 | 1 | 3µs | 1; | ||
49 | |||||
50 | # ABSTRACT: The Moose Type Coercion metaclass for Unions | ||||
51 | |||||
- - | |||||
54 | =pod | ||||
55 | |||||
56 | =head1 NAME | ||||
57 | |||||
58 | Moose::Meta::TypeCoercion::Union - The Moose Type Coercion metaclass for Unions | ||||
59 | |||||
60 | =head1 VERSION | ||||
61 | |||||
62 | version 2.0602 | ||||
63 | |||||
64 | =head1 DESCRIPTION | ||||
65 | |||||
66 | This is a subclass of L<Moose::Meta::TypeCoercion> that is used for | ||||
67 | L<Moose::Meta::TypeConstraint::Union> objects. | ||||
68 | =head1 METHODS | ||||
69 | |||||
70 | =over 4 | ||||
71 | |||||
72 | =item B<< $coercion->has_coercion_for_type >> | ||||
73 | |||||
74 | This method always returns false. | ||||
75 | |||||
76 | =item B<< $coercion->add_type_coercions >> | ||||
77 | |||||
78 | This method always throws an error. You cannot add coercions to a | ||||
79 | union type coercion. | ||||
80 | |||||
81 | =item B<< $coercion->coerce($value) >> | ||||
82 | |||||
83 | This method will coerce by trying the coercions for each type in the | ||||
84 | union. | ||||
85 | |||||
86 | =back | ||||
87 | |||||
88 | =head1 BUGS | ||||
89 | |||||
90 | See L<Moose/BUGS> for details on reporting bugs. | ||||
91 | |||||
92 | =head1 AUTHOR | ||||
93 | |||||
94 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
95 | |||||
96 | =head1 COPYRIGHT AND LICENSE | ||||
97 | |||||
98 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
99 | |||||
100 | This is free software; you can redistribute it and/or modify it under | ||||
101 | the same terms as the Perl 5 programming language system itself. | ||||
102 | |||||
103 | =cut | ||||
104 | |||||
105 | |||||
106 | __END__ |