| 1 | package Class::Method::ModifiersX::Override; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | no warnings qw( once void uninitialized ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | $Class::Method::ModifiersX::Override::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 10 | 3 | $Class::Method::ModifiersX::Override::VERSION = '0.003'; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 15 | all => [our @EXPORT_OK = our @EXPORT = qw( override super )], | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Class::Method::Modifiers qw( install_modifier ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | our $SUPER_PACKAGE = undef; | |||||||||||||||||||||||||||
| 22 | 3 | our $SUPER_BODY = undef; | |||||||||||||||||||||||||||
| 23 | 3 | our @SUPER_ARGS = (); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub _mk_around | ||||||||||||||||||||||||||||
| 26 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_mk_around: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 4 | my ($into, $code) = @_; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 6 | local $SUPER_PACKAGE = $into; | |||||||||||||||||||||||||||
| 31 | 6 | local $SUPER_BODY = shift; | |||||||||||||||||||||||||||
| 32 | 6 | local @SUPER_ARGS = @_; | |||||||||||||||||||||||||||
| 33 | 6 | return $code->(@_); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 4 | } | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 3 | our %OVERRIDDEN; | |||||||||||||||||||||||||||
| 38 | sub override | ||||||||||||||||||||||||||||
| 39 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
override: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 2 | my $into = caller(0); | |||||||||||||||||||||||||||
| 41 | 2 | my $code = pop; | |||||||||||||||||||||||||||
| 42 | 2 | my @name = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | for my $method (@name) | |||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | croak "Method '$method' in class '$into' overridden twice" | ||||||||||||||||||||||||||||
| 47 | 2 | ▶ | if $OVERRIDDEN{$into}{$method}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | my $sub = _mk_around($into, $code); | |||||||||||||||||||||||||||
| 51 | 2 | install_modifier($into, 'around', @name, $sub); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub super () | ||||||||||||||||||||||||||||
| 55 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
super: called CC=4 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 6 | ▶ | return unless defined $SUPER_BODY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 6 | ▶ | return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $Class::Method::ModifiersX::Override::SUPER_PACKAGE and $Class::Method::ModifiersX::Override::SUPER_PACKAGE ne caller
MC/DC0%0/2
defined $Class::Method::ModifiersX::Override::SUPER_PACKAGE and $Class::Method::ModifiersX::Override::SUPER_PACKAGE ne caller
defined $Class::Method::ModifiersX::Override::SUPER_PACKAGE
$Class::Method::ModifiersX::Override::SUPER_PACKAGE ne caller
Truth table33%1/3
A and B
A= defined $Class::Method::ModifiersX::Override::SUPER_PACKAGEB= $Class::Method::ModifiersX::Override::SUPER_PACKAGE ne caller
| |||||||||||||||||||||||||||||
| 58 | 6 | $SUPER_BODY->(@SUPER_ARGS); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||