| File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Method/Overridden.pm |
| Statements Executed | 13 |
| Statement Execution Time | 825µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 14µs | 17µs | Moose::Meta::Method::Overridden::BEGIN@3 |
| 1 | 1 | 1 | 9µs | 17µs | Moose::Meta::Method::Overridden::BEGIN@4 |
| 1 | 1 | 1 | 7µs | 1.09ms | Moose::Meta::Method::Overridden::BEGIN@10 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Overridden::__ANON__[:37] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Overridden::new |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::Method::Overridden; | ||||
| 2 | |||||
| 3 | 3 | 20µs | 2 | 20µs | # spent 17µs (14+3) within Moose::Meta::Method::Overridden::BEGIN@3 which was called
# once (14µs+3µs) by Moose::Meta::Class::BEGIN@18 at line 3 # spent 17µs making 1 call to Moose::Meta::Method::Overridden::BEGIN@3
# spent 3µs making 1 call to strict::import |
| 4 | 3 | 41µs | 2 | 26µs | # spent 17µs (9+9) within Moose::Meta::Method::Overridden::BEGIN@4 which was called
# once (9µs+9µs) by Moose::Meta::Class::BEGIN@18 at line 4 # spent 17µs making 1 call to Moose::Meta::Method::Overridden::BEGIN@4
# spent 9µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 1 | 3µs | our $VERSION = '0.98'; | ||
| 7 | 1 | 46µs | $VERSION = eval $VERSION; | ||
| 8 | 1 | 1µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 9 | |||||
| 10 | 3 | 702µs | 2 | 2.16ms | # spent 1.09ms (7µs+1.08) within Moose::Meta::Method::Overridden::BEGIN@10 which was called
# once (7µs+1.08ms) by Moose::Meta::Class::BEGIN@18 at line 10 # spent 1.09ms making 1 call to Moose::Meta::Method::Overridden::BEGIN@10
# spent 1.08ms making 1 call to base::import |
| 11 | |||||
| 12 | sub new { | ||||
| 13 | my ( $class, %args ) = @_; | ||||
| 14 | |||||
| 15 | # the package can be overridden by roles | ||||
| 16 | # it is really more like body's compilation stash | ||||
| 17 | # this is where we need to override the definition of super() so that the | ||||
| 18 | # body of the code can call the right overridden version | ||||
| 19 | my $super_package = $args{package} || $args{class}->name; | ||||
| 20 | |||||
| 21 | my $name = $args{name}; | ||||
| 22 | |||||
| 23 | my $super = $args{class}->find_next_method_by_name($name); | ||||
| 24 | |||||
| 25 | (defined $super) | ||||
| 26 | || $class->throw_error("You cannot override '$name' because it has no super method", data => $name); | ||||
| 27 | |||||
| 28 | my $super_body = $super->body; | ||||
| 29 | |||||
| 30 | my $method = $args{method}; | ||||
| 31 | |||||
| 32 | my $body = sub { | ||||
| 33 | local $Moose::SUPER_PACKAGE = $super_package; | ||||
| 34 | local @Moose::SUPER_ARGS = @_; | ||||
| 35 | local $Moose::SUPER_BODY = $super_body; | ||||
| 36 | return $method->(@_); | ||||
| 37 | }; | ||||
| 38 | |||||
| 39 | # FIXME do we need this make sure this works for next::method? | ||||
| 40 | # subname "${super_package}::${name}", $method; | ||||
| 41 | |||||
| 42 | # FIXME store additional attrs | ||||
| 43 | $class->wrap( | ||||
| 44 | $body, | ||||
| 45 | package_name => $args{class}->name, | ||||
| 46 | name => $name | ||||
| 47 | ); | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | 1 | 11µs | 1; | ||
| 51 | |||||
| 52 | __END__ | ||||
| 53 | |||||
| 54 | =pod | ||||
| 55 | |||||
| 56 | =head1 NAME | ||||
| 57 | |||||
| 58 | Moose::Meta::Method::Overridden - A Moose Method metaclass for overridden methods | ||||
| 59 | |||||
| 60 | =head1 DESCRIPTION | ||||
| 61 | |||||
| 62 | This class implements method overriding logic for the L<Moose> | ||||
| 63 | C<override> keyword. | ||||
| 64 | |||||
| 65 | The overriding subroutine's parent will be invoked explicitly using | ||||
| 66 | the C<super> keyword from the parent class's method definition. | ||||
| 67 | |||||
| 68 | =head1 METHODS | ||||
| 69 | |||||
| 70 | =over 4 | ||||
| 71 | |||||
| 72 | =item B<< Moose::Meta::Method::Overridden->new(%options) >> | ||||
| 73 | |||||
| 74 | This constructs a new object. It accepts the following options: | ||||
| 75 | |||||
| 76 | =over 8 | ||||
| 77 | |||||
| 78 | =item * class | ||||
| 79 | |||||
| 80 | The metaclass object for the class in which the override is being | ||||
| 81 | declared. This option is required. | ||||
| 82 | |||||
| 83 | =item * name | ||||
| 84 | |||||
| 85 | The name of the method which we are overriding. This method must exist | ||||
| 86 | in one of the class's superclasses. This option is required. | ||||
| 87 | |||||
| 88 | =item * method | ||||
| 89 | |||||
| 90 | The subroutine reference which implements the overriding. This option | ||||
| 91 | is required. | ||||
| 92 | |||||
| 93 | =back | ||||
| 94 | |||||
| 95 | =back | ||||
| 96 | |||||
| 97 | =head1 BUGS | ||||
| 98 | |||||
| 99 | See L<Moose/BUGS> for details on reporting bugs. | ||||
| 100 | |||||
| 101 | =head1 AUTHOR | ||||
| 102 | |||||
| 103 | Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt> | ||||
| 104 | |||||
| 105 | =head1 COPYRIGHT AND LICENSE | ||||
| 106 | |||||
| 107 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
| 108 | |||||
| 109 | L<http://www.iinteractive.com> | ||||
| 110 | |||||
| 111 | This library is free software; you can redistribute it and/or modify | ||||
| 112 | it under the same terms as Perl itself. | ||||
| 113 | |||||
| 114 | =cut |