File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Method/Destructor.pm |
Statements Executed | 158 |
Statement Execution Time | 1.38ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
6 | 1 | 1 | 693µs | 1.68ms | new | Moose::Meta::Method::Destructor::
6 | 1 | 1 | 131µs | 983µs | _initialize_body | Moose::Meta::Method::Destructor::
7 | 1 | 1 | 81µs | 1.11ms | is_needed | Moose::Meta::Method::Destructor::
1 | 1 | 1 | 16µs | 19µs | BEGIN@4 | Moose::Meta::Method::Destructor::
6 | 1 | 1 | 15µs | 15µs | options | Moose::Meta::Method::Destructor::
1 | 1 | 1 | 7µs | 16µs | BEGIN@5 | Moose::Meta::Method::Destructor::
1 | 1 | 1 | 6µs | 72µs | BEGIN@15 | Moose::Meta::Method::Destructor::
1 | 1 | 1 | 6µs | 34µs | BEGIN@8 | Moose::Meta::Method::Destructor::
1 | 1 | 1 | 3µs | 3µs | BEGIN@9 | Moose::Meta::Method::Destructor::
1 | 1 | 1 | 3µs | 3µs | BEGIN@7 | Moose::Meta::Method::Destructor::
0 | 0 | 0 | 0s | 0s | initialize_body | Moose::Meta::Method::Destructor::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Moose::Meta::Method::Destructor; | ||||
3 | |||||
4 | 3 | 21µs | 2 | 22µs | # spent 19µs (16+3) within Moose::Meta::Method::Destructor::BEGIN@4 which was called
# once (16µs+3µs) by Moose::Meta::Class::BEGIN@23 at line 4 # spent 19µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@4
# spent 3µs making 1 call to strict::import |
5 | 3 | 19µs | 2 | 26µs | # spent 16µs (7+9) within Moose::Meta::Method::Destructor::BEGIN@5 which was called
# once (7µs+9µs) by Moose::Meta::Class::BEGIN@23 at line 5 # spent 16µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@5
# spent 9µs making 1 call to warnings::import |
6 | |||||
7 | 3 | 18µs | 1 | 3µs | # spent 3µs within Moose::Meta::Method::Destructor::BEGIN@7 which was called
# once (3µs+0s) by Moose::Meta::Class::BEGIN@23 at line 7 # spent 3µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@7 |
8 | 3 | 20µs | 2 | 63µs | # spent 34µs (6+29) within Moose::Meta::Method::Destructor::BEGIN@8 which was called
# once (6µs+29µs) by Moose::Meta::Class::BEGIN@23 at line 8 # spent 34µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@8
# spent 28µs making 1 call to Exporter::import |
9 | 3 | 47µs | 1 | 3µs | # spent 3µs within Moose::Meta::Method::Destructor::BEGIN@9 which was called
# once (3µs+0s) by Moose::Meta::Class::BEGIN@23 at line 9 # spent 3µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@9 |
10 | |||||
11 | 1 | 700ns | our $VERSION = '0.98'; | ||
12 | 1 | 13µs | $VERSION = eval $VERSION; | ||
13 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
14 | |||||
15 | # spent 72µs (6+65) within Moose::Meta::Method::Destructor::BEGIN@15 which was called
# once (6µs+65µs) by Moose::Meta::Class::BEGIN@23 at line 16 # spent 66µs making 1 call to base::import | ||||
16 | 3 | 336µs | 1 | 72µs | 'Class::MOP::Method::Inlined'; # spent 72µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@15 |
17 | |||||
18 | # spent 1.68ms (693µs+988µs) within Moose::Meta::Method::Destructor::new which was called 6 times, avg 280µs/call:
# 6 times (693µs+988µs) by Class::MOP::Class::_inline_destructor at line 1089 of Class/MOP/Class.pm, avg 280µs/call | ||||
19 | 48 | 690µs | my $class = shift; | ||
20 | my %options = @_; | ||||
21 | |||||
22 | (ref $options{options} eq 'HASH') | ||||
23 | || $class->throw_error("You must pass a hash of options", data => $options{options}); | ||||
24 | |||||
25 | ($options{package_name} && $options{name}) | ||||
26 | || $class->throw_error("You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT"); | ||||
27 | |||||
28 | my $self = bless { | ||||
29 | # from our superclass | ||||
30 | 'body' => undef, | ||||
31 | 'package_name' => $options{package_name}, | ||||
32 | 'name' => $options{name}, | ||||
33 | # ... | ||||
34 | 'options' => $options{options}, | ||||
35 | 'associated_metaclass' => $options{metaclass}, | ||||
36 | } => $class; | ||||
37 | |||||
38 | # we don't want this creating | ||||
39 | # a cycle in the code, if not | ||||
40 | # needed | ||||
41 | weaken($self->{'associated_metaclass'}); # spent 5µs making 6 calls to Scalar::Util::weaken, avg 883ns/call | ||||
42 | |||||
43 | $self->_initialize_body; # spent 983µs making 6 calls to Moose::Meta::Method::Destructor::_initialize_body, avg 164µs/call | ||||
44 | |||||
45 | return $self; | ||||
46 | } | ||||
47 | |||||
48 | ## accessors | ||||
49 | |||||
50 | 6 | 18µs | # spent 15µs within Moose::Meta::Method::Destructor::options which was called 6 times, avg 2µs/call:
# 6 times (15µs+0s) by Moose::Meta::Method::Destructor::_initialize_body at line 106, avg 2µs/call | ||
51 | |||||
52 | ## method | ||||
53 | |||||
54 | # spent 1.11ms (81µs+1.03) within Moose::Meta::Method::Destructor::is_needed which was called 7 times, avg 159µs/call:
# 7 times (81µs+1.03ms) by Class::MOP::Class::_inline_destructor at line 1087 of Class/MOP/Class.pm, avg 159µs/call | ||||
55 | 28 | 88µs | my $self = shift; | ||
56 | my $metaclass = shift; | ||||
57 | |||||
58 | ( blessed $metaclass && $metaclass->isa('Class::MOP::Class') ) # spent 8µs making 7 calls to Scalar::Util::blessed, avg 1µs/call
# spent 8µs making 7 calls to UNIVERSAL::isa, avg 1µs/call | ||||
59 | || $self->throw_error( | ||||
60 | "The is_needed method expected a metaclass object as its arugment"); | ||||
61 | |||||
62 | return $metaclass->find_method_by_name("DEMOLISHALL"); # spent 1.02ms making 7 calls to Class::MOP::Class::find_method_by_name, avg 145µs/call | ||||
63 | } | ||||
64 | |||||
65 | sub initialize_body { | ||||
66 | Carp::cluck('The initialize_body method has been made private.' | ||||
67 | . " The public version is deprecated and will be removed in a future release.\n"); | ||||
68 | shift->_initialize_body; | ||||
69 | } | ||||
70 | |||||
71 | # spent 983µs (131+852) within Moose::Meta::Method::Destructor::_initialize_body which was called 6 times, avg 164µs/call:
# 6 times (131µs+852µs) by Moose::Meta::Method::Destructor::new at line 43, avg 164µs/call | ||||
72 | 48 | 100µs | my $self = shift; | ||
73 | # TODO: | ||||
74 | # the %options should also include a both | ||||
75 | # a call 'initializer' and call 'SUPER::' | ||||
76 | # options, which should cover approx 90% | ||||
77 | # of the possible use cases (even if it | ||||
78 | # requires some adaption on the part of | ||||
79 | # the author, after all, nothing is free) | ||||
80 | |||||
81 | my @DEMOLISH_methods = $self->associated_metaclass->find_all_methods_by_name('DEMOLISH'); # spent 492µs making 6 calls to Class::MOP::Class::find_all_methods_by_name, avg 82µs/call
# spent 6µs making 6 calls to Class::MOP::Method::associated_metaclass, avg 1µs/call | ||||
82 | |||||
83 | my $source; | ||||
84 | 6 | 5µs | if ( @DEMOLISH_methods ) { | ||
85 | $source = 'sub {'; | ||||
86 | $source .= 'my $self = shift;' . "\n"; | ||||
87 | |||||
88 | $source .= 'local $?;' . "\n"; | ||||
89 | |||||
90 | $source .= 'my $in_global_destruction = Devel::GlobalDestruction::in_global_destruction;' . "\n"; | ||||
91 | |||||
92 | $source .= 'Try::Tiny::try {' . "\n"; | ||||
93 | |||||
94 | $source .= '$self->' . $_->{class} . '::DEMOLISH($in_global_destruction);' . "\n" | ||||
95 | for @DEMOLISH_methods; | ||||
96 | |||||
97 | $source .= '}'; | ||||
98 | $source .= q[ Try::Tiny::catch { no warnings 'misc'; die $_ };] . "\n"; | ||||
99 | $source .= 'return;' . "\n"; | ||||
100 | |||||
101 | $source .= '}'; | ||||
102 | } else { | ||||
103 | $source = 'sub { }'; | ||||
104 | } | ||||
105 | |||||
106 | warn $source if $self->options->{debug}; # spent 15µs making 6 calls to Moose::Meta::Method::Destructor::options, avg 2µs/call | ||||
107 | |||||
108 | my ( $code, $e ) = $self->_compile_code( # spent 340µs making 6 calls to Class::MOP::Method::Generated::_compile_code, avg 57µs/call | ||||
109 | environment => {}, | ||||
110 | code => $source, | ||||
111 | ); | ||||
112 | |||||
113 | $self->throw_error( | ||||
114 | "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$e", | ||||
115 | error => $e, data => $source ) | ||||
116 | if $e; | ||||
117 | |||||
118 | $self->{'body'} = $code; | ||||
119 | } | ||||
120 | |||||
121 | |||||
122 | 1 | 9µs | 1; | ||
123 | |||||
124 | __END__ | ||||
125 | |||||
126 | =pod | ||||
127 | |||||
128 | =head1 NAME | ||||
129 | |||||
130 | Moose::Meta::Method::Destructor - Method Meta Object for destructors | ||||
131 | |||||
132 | =head1 DESCRIPTION | ||||
133 | |||||
134 | This class is a subclass of L<Class::MOP::Class::Generated> that | ||||
135 | provides Moose-specific functionality for inlining destructors. | ||||
136 | |||||
137 | To understand this class, you should read the the | ||||
138 | L<Class::MOP::Class::Generated> documentation as well. | ||||
139 | |||||
140 | =head1 INHERITANCE | ||||
141 | |||||
142 | C<Moose::Meta::Method::Destructor> is a subclass of | ||||
143 | L<Moose::Meta::Method> I<and> L<Class::MOP::Method::Generated>. | ||||
144 | |||||
145 | =head1 METHODS | ||||
146 | |||||
147 | =over 4 | ||||
148 | |||||
149 | =item B<< Moose::Meta;:Method::Destructor->new(%options) >> | ||||
150 | |||||
151 | This constructs a new object. It accepts the following options: | ||||
152 | |||||
153 | =over 8 | ||||
154 | |||||
155 | =item * package_name | ||||
156 | |||||
157 | The package for the class in which the destructor is being | ||||
158 | inlined. This option is required. | ||||
159 | |||||
160 | =item * name | ||||
161 | |||||
162 | The name of the destructor method. This option is required. | ||||
163 | |||||
164 | =item * metaclass | ||||
165 | |||||
166 | The metaclass for the class this destructor belongs to. This is | ||||
167 | optional, as it can be set later by calling C<< | ||||
168 | $metamethod->attach_to_class >>. | ||||
169 | |||||
170 | =back | ||||
171 | |||||
172 | =item B<< Moose::Meta;:Method::Destructor->is_needed($metaclass) >> | ||||
173 | |||||
174 | Given a L<Moose::Meta::Class> object, this method returns a boolean | ||||
175 | indicating whether the class needs a destructor. If the class or any | ||||
176 | of its parents defines a C<DEMOLISH> method, it needs a destructor. | ||||
177 | |||||
178 | =back | ||||
179 | |||||
180 | =head1 BUGS | ||||
181 | |||||
182 | See L<Moose/BUGS> for details on reporting bugs. | ||||
183 | |||||
184 | =head1 AUTHORS | ||||
185 | |||||
186 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
187 | |||||
188 | =head1 COPYRIGHT AND LICENSE | ||||
189 | |||||
190 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
191 | |||||
192 | L<http://www.iinteractive.com> | ||||
193 | |||||
194 | This library is free software; you can redistribute it and/or modify | ||||
195 | it under the same terms as Perl itself. | ||||
196 | |||||
197 | =cut | ||||
198 |