| 1 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 117 | package Mite::Trait::HasSuperclasses; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 117 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 117 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 117 | ▶ | no warnings qw( once void ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 117 | our $USES_MITE = "Mite::Role"; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 117 | our $MITE_SHIM = "Mite::Shim"; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 117 | our $MITE_VERSION = "0.013000"; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Mite keywords | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 117 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 117 | my ( $SHIM, $CALLER ) = | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | ( "Mite::Shim", "Mite::Trait::HasSuperclasses" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | *after, *around, *before, | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | *field, *has, *param, | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | *requires, *signature_for, *with | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 117 | = do { | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | package Mite::Shim; | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 117 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub { $SHIM->HANDLE_after( $CALLER, "role", @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 351 | ▶ | sub { $SHIM->HANDLE_around( $CALLER, "role", @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 117 | ▶ | sub { $SHIM->HANDLE_before( $CALLER, "role", @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 351 | ▶ | sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub { }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub { $SHIM->HANDLE_signature_for( $CALLER, "role", @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub { $SHIM->HANDLE_with( $CALLER, @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 117 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Mite imports | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 117 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 117 | require Scalar::Util; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 117 | *STRICT = \&Mite::Shim::STRICT; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 117 | *bare = \&Mite::Shim::bare; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 117 | *blessed = \&Scalar::Util::blessed; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 117 | *carp = \&Mite::Shim::carp; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 117 | *confess = \&Mite::Shim::confess; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 117 | *croak = \&Mite::Shim::croak; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 117 | *false = \&Mite::Shim::false; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 117 | *guard = \&Mite::Shim::guard; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 117 | *lazy = \&Mite::Shim::lazy; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 117 | *lock = \&Mite::Shim::lock; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 117 | *ro = \&Mite::Shim::ro; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 117 | *rw = \&Mite::Shim::rw; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 117 | *rwp = \&Mite::Shim::rwp; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 117 | *true = \&Mite::Shim::true; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 117 | *unlock = \&Mite::Shim::unlock; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Gather metadata for constructor and destructor | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub __META__ { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__META__: not called CC=4 SCAR=26.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 117 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $linear_isa = mro::get_linear_isa($class); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | return { | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | BUILD => [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | map { "$_\::BUILD" } reverse @$linear_isa | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | DEMOLISH => [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | map { "$_\::DEMOLISH" } @$linear_isa | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | HAS_BUILDARGS => $class->can('BUILDARGS'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'), | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # See UNIVERSAL | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub DOES { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DOES: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my ( $self, $role ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | our %DOES; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return $DOES{$role} if exists $DOES{$role}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return 1 if $role eq __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $INC{'Moose/Util.pm'} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$INC{"Moose/Util.pm"} and my $meta = Moose::Util::find_meta(ref $self || $self)
ref $self || $self
MC/DC0%0/2
$INC{"Moose/Util.pm"} and my $meta = Moose::Util::find_meta(ref $self || $self)
$INC{"Moose/Util.pm"}
my $meta = Moose::Util::find_meta(ref $self || $self)
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A and B
A= $INC{"Moose/Util.pm"}B= my $meta = Moose::Util::find_meta(ref $self || $self)
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | and my $meta = Moose::Util::find_meta( ref $self or $self ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $meta->can('does_role') and $meta->does_role($role) and return 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$meta->can("does_role") and $meta->does_role($role)
MC/DC0%0/2
$meta->can("does_role") and $meta->does_role($role)
$meta->can("does_role")
$meta->does_role($role)
Truth table0%0/3
A and B
A= $meta->can("does_role")B= $meta->does_role($role)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return $self->SUPER::DOES($role); | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Alias for Moose/Moo-compatibility | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub does { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
does: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | shift->DOES(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Callback which classes consuming this role will call | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 117 | ▶ | sub __FINALIZE_APPLICATION__ { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__FINALIZE_APPLICATION__: called CC=9 SCAR=22.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 117 | my ( $me, $target, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 117 | our ( %CONSUMERS, @METHOD_MODIFIERS ); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # Ensure a given target only consumes this role once. | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 117 | ▶ | if ( exists $CONSUMERS{$target} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 117 | $CONSUMERS{$target} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 117 | ▶ | my $type = do { no strict 'refs'; ${"$target\::USES_MITE"} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 117 | ▶ | return if $type ne 'Mite::Class'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 117 | my @missing_methods; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 117 | ▶ | @missing_methods = grep( !$target->can($_), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | "_compile_meta_method", "_compile_mop_postamble", | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | "compilation_stages", "inject_mite_functions" ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | and croak( "$me requires $target to implement methods: " . join q[, ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | @missing_methods ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 117 | my @roles = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 117 | ▶ | my %nextargs = %{ $args || {} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 117 | ▶ | ( $nextargs{-indirect} ||= 0 )++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$nextargs{"-indirect"} ||= 0
MC/DC0%0/1
$nextargs{"-indirect"} ||= 0
$nextargs{"-indirect"}
Truth table50%1/2
A
A= $nextargs{"-indirect"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 117 | ▶ | croak("PANIC!") if $nextargs{-indirect} > 100; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 117 | for my $role (@roles) { | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $role->__FINALIZE_APPLICATION__( $target, {%nextargs} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 117 | my $shim = "Mite::Shim"; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 117 | for my $modifier_rule (@METHOD_MODIFIERS) { | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 468 | my ( $modification, $names, $coderef ) = @$modifier_rule; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 468 | my $handler = "HANDLE_$modification"; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 468 | $shim->$handler( $target, "class", $names, $coderef ); | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 117 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 117 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||