File | /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types/Util.pm |
Statements Executed | 38 |
Statement Execution Time | 276µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 33µs | 35µs | filter_tags | MooseX::Types::Util::
1 | 1 | 1 | 16µs | 28µs | BEGIN@9 | MooseX::Types::Util::
1 | 1 | 1 | 9µs | 67µs | BEGIN@13 | MooseX::Types::Util::
1 | 1 | 1 | 8µs | 10µs | BEGIN@10 | MooseX::Types::Util::
1 | 1 | 1 | 8µs | 38µs | BEGIN@11 | MooseX::Types::Util::
10 | 1 | 2 | 2µs | 2µs | CORE:match (opcode) | MooseX::Types::Util::
0 | 0 | 0 | 0s | 0s | has_available_type_export | MooseX::Types::Util::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package MooseX::Types::Util; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
5 | MooseX::Types::Util - Common utility functions for the module | ||||
6 | |||||
7 | =cut | ||||
8 | |||||
9 | 3 | 23µs | 2 | 40µs | # spent 28µs (16+12) within MooseX::Types::Util::BEGIN@9 which was called
# once (16µs+12µs) by MooseX::Types::Base::BEGIN@11 at line 9 # spent 28µs making 1 call to MooseX::Types::Util::BEGIN@9
# spent 12µs making 1 call to warnings::import |
10 | 3 | 21µs | 2 | 12µs | # spent 10µs (8+2) within MooseX::Types::Util::BEGIN@10 which was called
# once (8µs+2µs) by MooseX::Types::Base::BEGIN@11 at line 10 # spent 10µs making 1 call to MooseX::Types::Util::BEGIN@10
# spent 2µs making 1 call to strict::import |
11 | 3 | 36µs | 2 | 69µs | # spent 38µs (8+31) within MooseX::Types::Util::BEGIN@11 which was called
# once (8µs+31µs) by MooseX::Types::Base::BEGIN@11 at line 11 # spent 38µs making 1 call to MooseX::Types::Util::BEGIN@11
# spent 31µs making 1 call to Exporter::import |
12 | |||||
13 | 3 | 154µs | 2 | 126µs | # spent 67µs (9+58) within MooseX::Types::Util::BEGIN@13 which was called
# once (9µs+58µs) by MooseX::Types::Base::BEGIN@11 at line 13 # spent 67µs making 1 call to MooseX::Types::Util::BEGIN@13
# spent 58µs making 1 call to base::import |
14 | |||||
15 | =head1 DESCRIPTION | ||||
16 | |||||
17 | This package the exportable functions that many parts in | ||||
18 | L<MooseX::Types> might need. | ||||
19 | |||||
20 | =cut | ||||
21 | |||||
22 | 1 | 1µs | our @EXPORT_OK = qw( filter_tags has_available_type_export ); | ||
23 | |||||
24 | =head1 FUNCTIONS | ||||
25 | |||||
26 | =head2 filter_tags | ||||
27 | |||||
28 | Takes a list and returns two references. The first is a hash reference | ||||
29 | containing the tags as keys and the number of their appearance as values. | ||||
30 | The second is an array reference containing all other elements. | ||||
31 | |||||
32 | =cut | ||||
33 | |||||
34 | # spent 35µs (33+2) within MooseX::Types::Util::filter_tags which was called
# once (33µs+2µs) by MooseX::Types::import at line 345 of MooseX/Types.pm | ||||
35 | 1 | 2µs | my (@list) = @_; | ||
36 | 1 | 800ns | my (%tags, @other); | ||
37 | 1 | 1µs | for (@list) { | ||
38 | 10 | 18µs | 10 | 2µs | if (/^:(.*)$/) { # spent 2µs making 10 calls to MooseX::Types::Util::CORE:match, avg 190ns/call |
39 | $tags{ $1 }++; | ||||
40 | next; | ||||
41 | } | ||||
42 | 10 | 5µs | push @other, $_; | ||
43 | } | ||||
44 | 1 | 5µs | return \%tags, \@other; | ||
45 | } | ||||
46 | |||||
47 | =head2 has_available_type_export | ||||
48 | |||||
49 | TypeConstraint | Undef = has_available_type_export($package, $name); | ||||
50 | |||||
51 | This function allows you to introspect if a given type export is available | ||||
52 | I<at this point in time>. This means that the C<$package> must have imported | ||||
53 | a typeconstraint with the name C<$name>, and it must be still in its symbol | ||||
54 | table. | ||||
55 | |||||
56 | Two arguments are expected: | ||||
57 | |||||
58 | =over 4 | ||||
59 | |||||
60 | =item $package | ||||
61 | |||||
62 | The name of the package to introspect. | ||||
63 | |||||
64 | =item $name | ||||
65 | |||||
66 | The name of the type export to introspect. | ||||
67 | |||||
68 | =back | ||||
69 | |||||
70 | B<Note> that the C<$name> is the I<exported> name of the type, not the declared | ||||
71 | one. This means that if you use L<Sub::Exporter>s functionality to rename an import | ||||
72 | like this: | ||||
73 | |||||
74 | use MyTypes Str => { -as => 'MyStr' }; | ||||
75 | |||||
76 | you would have to introspect this type like this: | ||||
77 | |||||
78 | has_available_type_export $package, 'MyStr'; | ||||
79 | |||||
80 | The return value will be either the type constraint that belongs to the export | ||||
81 | or an undefined value. | ||||
82 | |||||
83 | =cut | ||||
84 | |||||
85 | sub has_available_type_export { | ||||
86 | my ($package, $name) = @_; | ||||
87 | |||||
88 | my $sub = $package->can($name) | ||||
89 | or return undef; | ||||
90 | |||||
91 | return undef | ||||
92 | unless blessed $sub && $sub->isa('MooseX::Types::EXPORTED_TYPE_CONSTRAINT'); | ||||
93 | |||||
94 | return $sub->(); | ||||
95 | } | ||||
96 | |||||
97 | =head1 SEE ALSO | ||||
98 | |||||
99 | L<MooseX::Types::Moose>, L<Exporter> | ||||
100 | |||||
101 | =head1 AUTHOR | ||||
102 | |||||
103 | See L<MooseX::Types/AUTHOR>. | ||||
104 | |||||
105 | =head1 LICENSE | ||||
106 | |||||
107 | This program is free software; you can redistribute it and/or modify | ||||
108 | it under the same terms as perl itself. | ||||
109 | |||||
110 | =cut | ||||
111 | |||||
112 | 1 | 8µs | 1; | ||
# spent 2µs within MooseX::Types::Util::CORE:match which was called 10 times, avg 190ns/call:
# 10 times (2µs+0s) by MooseX::Types::Util::filter_tags at line 38 of MooseX/Types/Util.pm, avg 190ns/call |