| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Constructor.pm |
| Statements | Executed 892 statements in 4.39ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 30 | 1 | 1 | 1.50ms | 51.0ms | Class::MOP::Method::Constructor::_generate_constructor_method_inline |
| 30 | 1 | 1 | 787µs | 52.9ms | Class::MOP::Method::Constructor::new |
| 30 | 1 | 1 | 619µs | 619µs | Class::MOP::Method::Constructor::_new |
| 30 | 1 | 1 | 297µs | 51.3ms | Class::MOP::Method::Constructor::_initialize_body |
| 30 | 1 | 1 | 197µs | 5.67ms | Class::MOP::Method::Constructor::_eval_environment |
| 30 | 1 | 1 | 145µs | 18.8ms | Class::MOP::Method::Constructor::__ANON__[:111] |
| 1 | 1 | 1 | 20µs | 46µs | Class::MOP::Method::Constructor::BEGIN@11 |
| 1 | 1 | 1 | 12µs | 730µs | Class::MOP::Method::Constructor::BEGIN@17 |
| 1 | 1 | 1 | 10µs | 10µs | Class::MOP::Method::Constructor::BEGIN@3 |
| 1 | 1 | 1 | 9µs | 39µs | Class::MOP::Method::Constructor::BEGIN@14 |
| 1 | 1 | 1 | 9µs | 62µs | Class::MOP::Method::Constructor::BEGIN@13 |
| 1 | 1 | 1 | 9µs | 17µs | Class::MOP::Method::Constructor::BEGIN@10 |
| 1 | 1 | 1 | 8µs | 41µs | Class::MOP::Method::Constructor::BEGIN@15 |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Constructor::__ANON__[:115] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Constructor::__ANON__[:93] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Constructor::_generate_constructor_method |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Class::MOP::Method::Constructor; | ||||
| 3 | # spent 10µs within Class::MOP::Method::Constructor::BEGIN@3 which was called:
# once (10µs+0s) by Class::MOP::Class::BEGIN@16 at line 5 | ||||
| 4 | 1 | 5µs | $Class::MOP::Method::Constructor::AUTHORITY = 'cpan:STEVAN'; | ||
| 5 | 1 | 24µs | 1 | 10µs | } # spent 10µs making 1 call to Class::MOP::Method::Constructor::BEGIN@3 |
| 6 | { | ||||
| 7 | 2 | 1µs | $Class::MOP::Method::Constructor::VERSION = '2.0602'; | ||
| 8 | } | ||||
| 9 | |||||
| 10 | 3 | 20µs | 2 | 25µs | # spent 17µs (9+8) within Class::MOP::Method::Constructor::BEGIN@10 which was called:
# once (9µs+8µs) by Class::MOP::Class::BEGIN@16 at line 10 # spent 17µs making 1 call to Class::MOP::Method::Constructor::BEGIN@10
# spent 8µs making 1 call to strict::import |
| 11 | 3 | 96µs | 2 | 71µs | # spent 46µs (20+26) within Class::MOP::Method::Constructor::BEGIN@11 which was called:
# once (20µs+26µs) by Class::MOP::Class::BEGIN@16 at line 11 # spent 46µs making 1 call to Class::MOP::Method::Constructor::BEGIN@11
# spent 26µs making 1 call to warnings::import |
| 12 | |||||
| 13 | 3 | 24µs | 2 | 115µs | # spent 62µs (9+53) within Class::MOP::Method::Constructor::BEGIN@13 which was called:
# once (9µs+53µs) by Class::MOP::Class::BEGIN@16 at line 13 # spent 62µs making 1 call to Class::MOP::Method::Constructor::BEGIN@13
# spent 53µs making 1 call to Exporter::import |
| 14 | 3 | 20µs | 2 | 68µs | # spent 39µs (9+30) within Class::MOP::Method::Constructor::BEGIN@14 which was called:
# once (9µs+30µs) by Class::MOP::Class::BEGIN@16 at line 14 # spent 39µs making 1 call to Class::MOP::Method::Constructor::BEGIN@14
# spent 30µs making 1 call to Exporter::import |
| 15 | 3 | 24µs | 2 | 74µs | # spent 41µs (8+33) within Class::MOP::Method::Constructor::BEGIN@15 which was called:
# once (8µs+33µs) by Class::MOP::Class::BEGIN@16 at line 15 # spent 41µs making 1 call to Class::MOP::Method::Constructor::BEGIN@15
# spent 33µs making 1 call to Exporter::import |
| 16 | |||||
| 17 | 3 | 412µs | 2 | 1.45ms | # spent 730µs (12+717) within Class::MOP::Method::Constructor::BEGIN@17 which was called:
# once (12µs+717µs) by Class::MOP::Class::BEGIN@16 at line 17 # spent 730µs making 1 call to Class::MOP::Method::Constructor::BEGIN@17
# spent 717µs making 1 call to base::import |
| 18 | |||||
| 19 | # spent 52.9ms (787µs+52.1) within Class::MOP::Method::Constructor::new which was called 30 times, avg 1.76ms/call:
# 30 times (787µs+52.1ms) by Class::MOP::Class::_inline_constructor at line 1438 of Class/MOP/Class.pm, avg 1.76ms/call | ||||
| 20 | 30 | 29µs | my $class = shift; | ||
| 21 | 30 | 140µs | my %options = @_; | ||
| 22 | |||||
| 23 | 30 | 240µs | 60 | 67µs | (blessed $options{metaclass} && $options{metaclass}->isa('Class::MOP::Class')) # spent 37µs making 30 calls to UNIVERSAL::isa, avg 1µs/call
# spent 31µs making 30 calls to Scalar::Util::blessed, avg 1µs/call |
| 24 | || confess "You must pass a metaclass instance if you want to inline" | ||||
| 25 | if $options{is_inline}; | ||||
| 26 | |||||
| 27 | 30 | 24µs | ($options{package_name} && $options{name}) | ||
| 28 | || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT"; | ||||
| 29 | |||||
| 30 | 30 | 86µs | 30 | 619µs | my $self = $class->_new(\%options); # spent 619µs making 30 calls to Class::MOP::Method::Constructor::_new, avg 21µs/call |
| 31 | |||||
| 32 | # we don't want this creating | ||||
| 33 | # a cycle in the code, if not | ||||
| 34 | # needed | ||||
| 35 | 30 | 97µs | 30 | 29µs | weaken($self->{'associated_metaclass'}); # spent 29µs making 30 calls to Scalar::Util::weaken, avg 980ns/call |
| 36 | |||||
| 37 | 30 | 86µs | 30 | 51.3ms | $self->_initialize_body; # spent 51.3ms making 30 calls to Class::MOP::Method::Constructor::_initialize_body, avg 1.71ms/call |
| 38 | |||||
| 39 | 30 | 134µs | return $self; | ||
| 40 | } | ||||
| 41 | |||||
| 42 | # spent 619µs within Class::MOP::Method::Constructor::_new which was called 30 times, avg 21µs/call:
# 30 times (619µs+0s) by Class::MOP::Method::Constructor::new at line 30, avg 21µs/call | ||||
| 43 | 30 | 15µs | my $class = shift; | ||
| 44 | |||||
| 45 | 30 | 18µs | return Class::MOP::Class->initialize($class)->new_object(@_) | ||
| 46 | if $class ne __PACKAGE__; | ||||
| 47 | |||||
| 48 | 30 | 32µs | my $params = @_ == 1 ? $_[0] : {@_}; | ||
| 49 | |||||
| 50 | 30 | 590µs | return bless { | ||
| 51 | # inherited from Class::MOP::Method | ||||
| 52 | body => $params->{body}, | ||||
| 53 | # associated_metaclass => $params->{associated_metaclass}, # overriden | ||||
| 54 | package_name => $params->{package_name}, | ||||
| 55 | name => $params->{name}, | ||||
| 56 | original_method => $params->{original_method}, | ||||
| 57 | |||||
| 58 | # inherited from Class::MOP::Generated | ||||
| 59 | is_inline => $params->{is_inline} || 0, | ||||
| 60 | definition_context => $params->{definition_context}, | ||||
| 61 | |||||
| 62 | # inherited from Class::MOP::Inlined | ||||
| 63 | _expected_method_class => $params->{_expected_method_class}, | ||||
| 64 | |||||
| 65 | # defined in this subclass | ||||
| 66 | options => $params->{options} || {}, | ||||
| 67 | associated_metaclass => $params->{metaclass}, | ||||
| 68 | }, $class; | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | ## accessors | ||||
| 72 | |||||
| 73 | 30 | 89µs | sub options { (shift)->{'options'} } | ||
| 74 | 90 | 210µs | sub associated_metaclass { (shift)->{'associated_metaclass'} } | ||
| 75 | |||||
| 76 | ## method | ||||
| 77 | |||||
| 78 | # spent 51.3ms (297µs+51.1) within Class::MOP::Method::Constructor::_initialize_body which was called 30 times, avg 1.71ms/call:
# 30 times (297µs+51.1ms) by Class::MOP::Method::Constructor::new at line 37, avg 1.71ms/call | ||||
| 79 | 30 | 15µs | my $self = shift; | ||
| 80 | 30 | 17µs | my $method_name = '_generate_constructor_method'; | ||
| 81 | |||||
| 82 | 30 | 104µs | 30 | 27µs | $method_name .= '_inline' if $self->is_inline; # spent 27µs making 30 calls to Class::MOP::Method::Generated::is_inline, avg 883ns/call |
| 83 | |||||
| 84 | 30 | 186µs | 30 | 51.0ms | $self->{'body'} = $self->$method_name; # spent 51.0ms making 30 calls to Class::MOP::Method::Constructor::_generate_constructor_method_inline, avg 1.70ms/call |
| 85 | } | ||||
| 86 | |||||
| 87 | # spent 5.67ms (197µs+5.47) within Class::MOP::Method::Constructor::_eval_environment which was called 30 times, avg 189µs/call:
# 30 times (197µs+5.47ms) by Class::MOP::Method::Generated::_compile_code at line 59 of Class/MOP/Method/Generated.pm, avg 189µs/call | ||||
| 88 | 30 | 12µs | my $self = shift; | ||
| 89 | 30 | 137µs | 60 | 5.47ms | return $self->associated_metaclass->_eval_environment; # spent 5.44ms making 30 calls to Class::MOP::Class::_eval_environment, avg 181µs/call
# spent 31µs making 30 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 1µs/call |
| 90 | } | ||||
| 91 | |||||
| 92 | sub _generate_constructor_method { | ||||
| 93 | return sub { Class::MOP::Class->initialize(shift)->new_object(@_) } | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | # spent 51.0ms (1.50+49.5) within Class::MOP::Method::Constructor::_generate_constructor_method_inline which was called 30 times, avg 1.70ms/call:
# 30 times (1.50ms+49.5ms) by Class::MOP::Method::Constructor::_initialize_body at line 84, avg 1.70ms/call | ||||
| 97 | 30 | 11µs | my $self = shift; | ||
| 98 | |||||
| 99 | 30 | 49µs | 30 | 37µs | my $meta = $self->associated_metaclass; # spent 37µs making 30 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 1µs/call |
| 100 | |||||
| 101 | 30 | 719µs | 30 | 29.9ms | my @source = ( # spent 29.9ms making 30 calls to Class::MOP::Class::_inline_new_object, avg 998µs/call |
| 102 | 'sub {', | ||||
| 103 | $meta->_inline_new_object, | ||||
| 104 | '}', | ||||
| 105 | ); | ||||
| 106 | |||||
| 107 | 30 | 75µs | 30 | 55µs | warn join("\n", @source) if $self->options->{debug}; # spent 55µs making 30 calls to Class::MOP::Method::Constructor::options, avg 2µs/call |
| 108 | |||||
| 109 | # spent 18.8ms (145µs+18.7) within Class::MOP::Method::Constructor::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Constructor.pm:111] which was called 30 times, avg 627µs/call:
# 30 times (145µs+18.7ms) by Try::Tiny::try at line 71 of Try/Tiny.pm, avg 627µs/call | ||||
| 110 | 30 | 134µs | 30 | 18.7ms | $self->_compile_code(\@source); # spent 18.7ms making 30 calls to Class::MOP::Method::Generated::_compile_code, avg 622µs/call |
| 111 | } | ||||
| 112 | catch { | ||||
| 113 | my $source = join("\n", @source); | ||||
| 114 | confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$_"; | ||||
| 115 | 30 | 356µs | 60 | 19.5ms | }; # spent 19.4ms making 30 calls to Try::Tiny::try, avg 645µs/call
# spent 140µs making 30 calls to Try::Tiny::catch, avg 5µs/call |
| 116 | |||||
| 117 | 30 | 157µs | return $code; | ||
| 118 | } | ||||
| 119 | |||||
| 120 | 1 | 3µs | 1; | ||
| 121 | |||||
| 122 | # ABSTRACT: Method Meta Object for constructors | ||||
| 123 | |||||
| - - | |||||
| 126 | =pod | ||||
| 127 | |||||
| 128 | =head1 NAME | ||||
| 129 | |||||
| 130 | Class::MOP::Method::Constructor - Method Meta Object for constructors | ||||
| 131 | |||||
| 132 | =head1 VERSION | ||||
| 133 | |||||
| 134 | version 2.0602 | ||||
| 135 | |||||
| 136 | =head1 SYNOPSIS | ||||
| 137 | |||||
| 138 | use Class::MOP::Method::Constructor; | ||||
| 139 | |||||
| 140 | my $constructor = Class::MOP::Method::Constructor->new( | ||||
| 141 | metaclass => $metaclass, | ||||
| 142 | options => { | ||||
| 143 | debug => 1, # this is all for now | ||||
| 144 | }, | ||||
| 145 | ); | ||||
| 146 | |||||
| 147 | # calling the constructor ... | ||||
| 148 | $constructor->body->execute($metaclass->name, %params); | ||||
| 149 | |||||
| 150 | =head1 DESCRIPTION | ||||
| 151 | |||||
| 152 | This is a subclass of C<Class::MOP::Method> which generates | ||||
| 153 | constructor methods. | ||||
| 154 | |||||
| 155 | =head1 METHODS | ||||
| 156 | |||||
| 157 | =over 4 | ||||
| 158 | |||||
| 159 | =item B<< Class::MOP::Method::Constructor->new(%options) >> | ||||
| 160 | |||||
| 161 | This creates a new constructor object. It accepts a hash reference of | ||||
| 162 | options. | ||||
| 163 | |||||
| 164 | =over 8 | ||||
| 165 | |||||
| 166 | =item * metaclass | ||||
| 167 | |||||
| 168 | This should be a L<Class::MOP::Class> object. It is required. | ||||
| 169 | |||||
| 170 | =item * name | ||||
| 171 | |||||
| 172 | The method name (without a package name). This is required. | ||||
| 173 | |||||
| 174 | =item * package_name | ||||
| 175 | |||||
| 176 | The package name for the method. This is required. | ||||
| 177 | |||||
| 178 | =item * is_inline | ||||
| 179 | |||||
| 180 | This indicates whether or not the constructor should be inlined. This | ||||
| 181 | defaults to false. | ||||
| 182 | |||||
| 183 | =back | ||||
| 184 | |||||
| 185 | =item B<< $metamethod->is_inline >> | ||||
| 186 | |||||
| 187 | Returns a boolean indicating whether or not the constructor is | ||||
| 188 | inlined. | ||||
| 189 | |||||
| 190 | =item B<< $metamethod->associated_metaclass >> | ||||
| 191 | |||||
| 192 | This returns the L<Class::MOP::Class> object for the method. | ||||
| 193 | |||||
| 194 | =back | ||||
| 195 | |||||
| 196 | =head1 AUTHOR | ||||
| 197 | |||||
| 198 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
| 199 | |||||
| 200 | =head1 COPYRIGHT AND LICENSE | ||||
| 201 | |||||
| 202 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
| 203 | |||||
| 204 | This is free software; you can redistribute it and/or modify it under | ||||
| 205 | the same terms as the Perl 5 programming language system itself. | ||||
| 206 | |||||
| 207 | =cut | ||||
| 208 | |||||
| 209 | |||||
| 210 | __END__ |