Profile of Moose/Meta/Method/Destructor.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:32 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/Method/Destructor.pm
Statements | Executed 22 statements in 553µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 8µs | 8µs | Moose::Meta::Method::Destructor::::BEGIN@3Moose::Meta::Method::Destructor::BEGIN@3
1 | 1 | 1 | 7µs | 32µs | Moose::Meta::Method::Destructor::::BEGIN@14Moose::Meta::Method::Destructor::BEGIN@14
1 | 1 | 1 | 7µs | 9µs | Moose::Meta::Method::Destructor::::BEGIN@10Moose::Meta::Method::Destructor::BEGIN@10
1 | 1 | 1 | 7µs | 15µs | Moose::Meta::Method::Destructor::::BEGIN@11Moose::Meta::Method::Destructor::BEGIN@11
1 | 1 | 1 | 7µs | 35µs | Moose::Meta::Method::Destructor::::BEGIN@15Moose::Meta::Method::Destructor::BEGIN@15
1 | 1 | 1 | 6µs | 132µs | Moose::Meta::Method::Destructor::::BEGIN@17Moose::Meta::Method::Destructor::BEGIN@17
1 | 1 | 1 | 4µs | 4µs | Moose::Meta::Method::Destructor::::BEGIN@13Moose::Meta::Method::Destructor::BEGIN@13
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::__ANON__[:107]Moose::Meta::Method::Destructor::__ANON__[:107]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::__ANON__[:99]Moose::Meta::Method::Destructor::__ANON__[:99]
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::_generate_DEMOLISHALLMoose::Meta::Method::Destructor::_generate_DEMOLISHALL
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::_generate_fallback_destructorMoose::Meta::Method::Destructor::_generate_fallback_destructor
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::_initialize_bodyMoose::Meta::Method::Destructor::_initialize_body
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::initialize_bodyMoose::Meta::Method::Destructor::initialize_body
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::is_neededMoose::Meta::Method::Destructor::is_needed
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::newMoose::Meta::Method::Destructor::new
0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Destructor::::optionsMoose::Meta::Method::Destructor::options

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  |
2 |  |  |  |  | package Moose::Meta::Method::Destructor;
3 |  |  |  |  | # spent 8µs within Moose::Meta::Method::Destructor::BEGIN@3 which was called: # once (8µs+0s) by Moose::Meta::Class::BEGIN@26 at line 5 BEGIN {
4 | 1 | 4µs |  |  | $Moose::Meta::Method::Destructor::AUTHORITY = 'cpan:STEVAN';
5 | 1 | 23µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@3
6 |  |  |  |  | {
7 | 2 | 1µs |  |  | $Moose::Meta::Method::Destructor::VERSION = '2.0602';
8 |  |  |  |  | }
9 |  |  |  |  |
10 | 3 | 16µs | 2 | 11µs | # spent 9µs (7+2) within Moose::Meta::Method::Destructor::BEGIN@10 which was called: # once (7µs+2µs) by Moose::Meta::Class::BEGIN@26 at line 10 use strict; # spent 9µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@10 # spent 2µs making 1 call to strict::import
11 | 3 | 16µs | 2 | 23µs | # spent 15µs (7+8) within Moose::Meta::Method::Destructor::BEGIN@11 which was called: # once (7µs+8µs) by Moose::Meta::Class::BEGIN@26 at line 11 use warnings; # spent 15µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@11 # spent 8µs making 1 call to warnings::import
12 |  |  |  |  |
13 | 3 | 28µs | 1 | 4µs | # spent 4µs within Moose::Meta::Method::Destructor::BEGIN@13 which was called: # once (4µs+0s) by Moose::Meta::Class::BEGIN@26 at line 13 use Devel::GlobalDestruction (); # spent 4µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@13
14 | 3 | 17µs | 2 | 57µs | # spent 32µs (7+25) within Moose::Meta::Method::Destructor::BEGIN@14 which was called: # once (7µs+25µs) by Moose::Meta::Class::BEGIN@26 at line 14 use Scalar::Util 'blessed', 'weaken'; # spent 32µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@14 # spent 25µs making 1 call to Exporter::import
15 | 3 | 19µs | 2 | 64µs | # spent 35µs (7+29) within Moose::Meta::Method::Destructor::BEGIN@15 which was called: # once (7µs+29µs) by Moose::Meta::Class::BEGIN@26 at line 15 use Try::Tiny; # spent 35µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@15 # spent 29µs making 1 call to Exporter::import
16 |  |  |  |  |
17 | 1 | 4µs | 1 | 126µs | # spent 132µs (6+126) within Moose::Meta::Method::Destructor::BEGIN@17 which was called: # once (6µs+126µs) by Moose::Meta::Class::BEGIN@26 at line 18 use base 'Moose::Meta::Method', # spent 126µs making 1 call to base::import
18 | 2 | 422µs | 1 | 132µs | 'Class::MOP::Method::Inlined'; # spent 132µs making 1 call to Moose::Meta::Method::Destructor::BEGIN@17
19 |  |  |  |  |
20 |  |  |  |  | sub new {
21 |  |  |  |  | my $class = shift;
22 |  |  |  |  | my %options = @_;
23 |  |  |  |  |
24 |  |  |  |  | (ref $options{options} eq 'HASH')
25 |  |  |  |  | || $class->throw_error("You must pass a hash of options", data => $options{options});
26 |  |  |  |  |
27 |  |  |  |  | ($options{package_name} && $options{name})
28 |  |  |  |  | || $class->throw_error("You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT");
29 |  |  |  |  |
30 |  |  |  |  | my $self = bless {
31 |  |  |  |  | # from our superclass
32 |  |  |  |  | 'body' => undef,
33 |  |  |  |  | 'package_name' => $options{package_name},
34 |  |  |  |  | 'name' => $options{name},
35 |  |  |  |  | # ...
36 |  |  |  |  | 'options' => $options{options},
37 |  |  |  |  | 'definition_context' => $options{definition_context},
38 |  |  |  |  | 'associated_metaclass' => $options{metaclass},
39 |  |  |  |  | } => $class;
40 |  |  |  |  |
41 |  |  |  |  | # we don't want this creating
42 |  |  |  |  | # a cycle in the code, if not
43 |  |  |  |  | # needed
44 |  |  |  |  | weaken($self->{'associated_metaclass'});
45 |  |  |  |  |
46 |  |  |  |  | $self->_initialize_body;
47 |  |  |  |  |
48 |  |  |  |  | return $self;
49 |  |  |  |  | }
50 |  |  |  |  |
51 |  |  |  |  | ## accessors
52 |  |  |  |  |
53 |  |  |  |  | sub options { (shift)->{'options'} }
54 |  |  |  |  |
55 |  |  |  |  | ## method
56 |  |  |  |  |
57 |  |  |  |  | sub is_needed {
58 |  |  |  |  | my $self = shift;
59 |  |  |  |  | my $metaclass = shift;
60 |  |  |  |  |
61 |  |  |  |  | ( blessed $metaclass && $metaclass->isa('Class::MOP::Class') )
62 |  |  |  |  | || $self->throw_error(
63 |  |  |  |  | "The is_needed method expected a metaclass object as its arugment");
64 |  |  |  |  |
65 |  |  |  |  | return $metaclass->find_method_by_name("DEMOLISHALL");
66 |  |  |  |  | }
67 |  |  |  |  |
68 |  |  |  |  | sub initialize_body {
69 |  |  |  |  | Carp::cluck('The initialize_body method has been made private.'
70 |  |  |  |  | . " The public version is deprecated and will be removed in a future release.\n");
71 |  |  |  |  | shift->_initialize_body;
72 |  |  |  |  | }
73 |  |  |  |  |
74 |  |  |  |  | sub _initialize_body {
75 |  |  |  |  | my $self = shift;
76 |  |  |  |  | # TODO:
77 |  |  |  |  | # the %options should also include a both
78 |  |  |  |  | # a call 'initializer' and call 'SUPER::'
79 |  |  |  |  | # options, which should cover approx 90%
80 |  |  |  |  | # of the possible use cases (even if it
81 |  |  |  |  | # requires some adaption on the part of
82 |  |  |  |  | # the author, after all, nothing is free)
83 |  |  |  |  |
84 |  |  |  |  | my $class = $self->associated_metaclass->name;
85 |  |  |  |  | my @source = (
86 |  |  |  |  | 'sub {',
87 |  |  |  |  | 'my $self = shift;',
88 |  |  |  |  | 'return ' . $self->_generate_fallback_destructor('$self'),
89 |  |  |  |  | 'if Scalar::Util::blessed($self) ne \'' . $class . '\';',
90 |  |  |  |  | 'local $?;',
91 |  |  |  |  | $self->_generate_DEMOLISHALL('$self'),
92 |  |  |  |  | 'return;',
93 |  |  |  |  | '}',
94 |  |  |  |  | );
95 |  |  |  |  | warn join("\n", @source) if $self->options->{debug};
96 |  |  |  |  |
97 |  |  |  |  | my $code = try {
98 |  |  |  |  | $self->_compile_code(source => \@source);
99 |  |  |  |  | }
100 |  |  |  |  | catch {
101 |  |  |  |  | my $source = join("\n", @source);
102 |  |  |  |  | $self->throw_error(
103 |  |  |  |  | "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$_",
104 |  |  |  |  | error => $_,
105 |  |  |  |  | data => $source,
106 |  |  |  |  | );
107 |  |  |  |  | };
108 |  |  |  |  |
109 |  |  |  |  | $self->{'body'} = $code;
110 |  |  |  |  | }
111 |  |  |  |  |
112 |  |  |  |  | sub _generate_fallback_destructor {
113 |  |  |  |  | my $self = shift;
114 |  |  |  |  | my ($inv) = @_;
115 |  |  |  |  |
116 |  |  |  |  | return $inv . '->Moose::Object::DESTROY(@_)';
117 |  |  |  |  | }
118 |  |  |  |  |
119 |  |  |  |  | sub _generate_DEMOLISHALL {
120 |  |  |  |  | my $self = shift;
121 |  |  |  |  | my ($inv) = @_;
122 |  |  |  |  |
123 |  |  |  |  | my @methods = $self->associated_metaclass->find_all_methods_by_name('DEMOLISH');
124 |  |  |  |  | return unless @methods;
125 |  |  |  |  |
126 |  |  |  |  | return (
127 |  |  |  |  | 'my $igd = Devel::GlobalDestruction::in_global_destruction;',
128 |  |  |  |  | 'Try::Tiny::try {',
129 |  |  |  |  | (map { $inv . '->' . $_->{class} . '::DEMOLISH($igd);' } @methods),
130 |  |  |  |  | '}',
131 |  |  |  |  | 'Try::Tiny::catch {',
132 |  |  |  |  | 'die $_;',
133 |  |  |  |  | '};',
134 |  |  |  |  | );
135 |  |  |  |  | }
136 |  |  |  |  |
137 |  |  |  |  |
138 | 1 | 2µs |  |  | 1;
139 |  |  |  |  |
140 |  |  |  |  | # ABSTRACT: Method Meta Object for destructors
141 |  |  |  |  |
- - |  |  |  |  |
144 |  |  |  |  | =pod
145 |  |  |  |  |
146 |  |  |  |  | =head1 NAME
147 |  |  |  |  |
148 |  |  |  |  | Moose::Meta::Method::Destructor - Method Meta Object for destructors
149 |  |  |  |  |
150 |  |  |  |  | =head1 VERSION
151 |  |  |  |  |
152 |  |  |  |  | version 2.0602
153 |  |  |  |  |
154 |  |  |  |  | =head1 DESCRIPTION
155 |  |  |  |  |
156 |  |  |  |  | This class is a subclass of L<Class::MOP::Method::Inlined> that
157 |  |  |  |  | provides Moose-specific functionality for inlining destructors.
158 |  |  |  |  |
159 |  |  |  |  | To understand this class, you should read the the
160 |  |  |  |  | L<Class::MOP::Method::Inlined> documentation as well.
161 |  |  |  |  |
162 |  |  |  |  | =head1 INHERITANCE
163 |  |  |  |  |
164 |  |  |  |  | C<Moose::Meta::Method::Destructor> is a subclass of
165 |  |  |  |  | L<Moose::Meta::Method> I<and> L<Class::MOP::Method::Inlined>.
166 |  |  |  |  |
167 |  |  |  |  | =head1 METHODS
168 |  |  |  |  |
169 |  |  |  |  | =over 4
170 |  |  |  |  |
171 |  |  |  |  | =item B<< Moose::Meta::Method::Destructor->new(%options) >>
172 |  |  |  |  |
173 |  |  |  |  | This constructs a new object. It accepts the following options:
174 |  |  |  |  |
175 |  |  |  |  | =over 8
176 |  |  |  |  |
177 |  |  |  |  | =item * package_name
178 |  |  |  |  |
179 |  |  |  |  | The package for the class in which the destructor is being
180 |  |  |  |  | inlined. This option is required.
181 |  |  |  |  |
182 |  |  |  |  | =item * name
183 |  |  |  |  |
184 |  |  |  |  | The name of the destructor method. This option is required.
185 |  |  |  |  |
186 |  |  |  |  | =item * metaclass
187 |  |  |  |  |
188 |  |  |  |  | The metaclass for the class this destructor belongs to. This is
189 |  |  |  |  | optional, as it can be set later by calling C<<
190 |  |  |  |  | $metamethod->attach_to_class >>.
191 |  |  |  |  |
192 |  |  |  |  | =back
193 |  |  |  |  |
194 |  |  |  |  | =item B<< Moose::Meta;:Method::Destructor->is_needed($metaclass) >>
195 |  |  |  |  |
196 |  |  |  |  | Given a L<Moose::Meta::Class> object, this method returns a boolean
197 |  |  |  |  | indicating whether the class needs a destructor. If the class or any
198 |  |  |  |  | of its parents defines a C<DEMOLISH> method, it needs a destructor.
199 |  |  |  |  |
200 |  |  |  |  | =back
201 |  |  |  |  |
202 |  |  |  |  | =head1 BUGS
203 |  |  |  |  |
204 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
205 |  |  |  |  |
206 |  |  |  |  | =head1 AUTHOR
207 |  |  |  |  |
208 |  |  |  |  | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
209 |  |  |  |  |
210 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
211 |  |  |  |  |
212 |  |  |  |  | This software is copyright (c) 2012 by Infinity Interactive, Inc..
213 |  |  |  |  |
214 |  |  |  |  | This is free software; you can redistribute it and/or modify it under
215 |  |  |  |  | the same terms as the Perl 5 programming language system itself.
216 |  |  |  |  |
217 |  |  |  |  | =cut
218 |  |  |  |  |
219 |  |  |  |  |
220 |  |  |  |  | __END__