| 1 | 117 | ▶ | use 5.010001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 117 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 117 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Mite::Trait::HasSuperclasses; | ||||||||||||||||||||
| 6 | 117 | ▶ | use Mite::Miteception -role, -all; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 117 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||
| 9 | 117 | our $VERSION = '0.013000'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # Super classes as class names | ||||||||||||||||||||
| 12 | has extends => | ||||||||||||||||||||
| 13 | is => bare, | ||||||||||||||||||||
| 14 | accessor => 'superclasses', | ||||||||||||||||||||
| 15 | isa => ArrayRef[ValidClassName], | ||||||||||||||||||||
| 16 | 146 | ▶ | default => sub { [] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | default_does_trigger => true, | ||||||||||||||||||||
| 18 | 181 | ▶ | trigger => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 19 | 181 | my $self = shift; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 181 | ▶ | return if !$self->name; # called from constructor | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # Set up our @ISA so we can use mro to calculate the class hierarchy | ||||||||||||||||||||
| 24 | 181 | $self->_set_isa; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # Allow $self->parents to recalculate itself | ||||||||||||||||||||
| 27 | 181 | $self->_clear_parents; | |||||||||||||||||||
| 28 | 117 | }; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | has superclass_args => | ||||||||||||||||||||
| 31 | is => rw, | ||||||||||||||||||||
| 32 | isa => Map[ NonEmptyStr, HashRef|Undef ], | ||||||||||||||||||||
| 33 | 146 | ▶ | builder => sub { {} }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # Super classes as Mite::Classes populated from $self->superclasses | ||||||||||||||||||||
| 36 | 117 | has parents => | |||||||||||||||||||
| 37 | is => ro, | ||||||||||||||||||||
| 38 | isa => ArrayRef[MiteClass], | ||||||||||||||||||||
| 39 | # Build on demand to allow the project to load all the classes first | ||||||||||||||||||||
| 40 | lazy => true, | ||||||||||||||||||||
| 41 | builder => '_build_parents', | ||||||||||||||||||||
| 42 | clearer => '_clear_parents'; | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 181 | ▶ | sub _set_isa { | ||||||||||||||||||
|
Subroutine
_set_isa: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | 181 | my $self = shift; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 181 | my $name = $self->name; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 181 | mro::set_mro($name, "c3"); | |||||||||||||||||||
| 50 | 117 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 181 | @{$name.'::ISA'} = @{$self->superclasses}; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 181 | return; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | ▶ | sub get_isa { | ||||||||||||||||||
|
Subroutine
get_isa: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 57 | 4 | my $self = shift; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 4 | my $name = $self->name; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 117 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 62 | 4 | return @{$name.'::ISA'}; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 639 | ▶ | sub linear_isa { | ||||||||||||||||||
|
Subroutine
linear_isa: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 66 | 639 | my $self = shift; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 639 | return @{mro::get_linear_isa($self->name)}; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 67 | ▶ | sub linear_parents { | ||||||||||||||||||
|
Subroutine
linear_parents: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 72 | 67 | my $self = shift; | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 67 | my $project = $self->project; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 67 | return grep defined, map { $project->class($_) } $self->linear_isa; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 23 | ▶ | sub handle_extends_keyword { | ||||||||||||||||||
|
Subroutine
handle_extends_keyword: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 80 | 23 | my $self = shift; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 23 | my ( @extends, %extends_args ); | |||||||||||||||||||
| 83 | 23 | ▶ | while ( @_ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 25 | my $class = shift; | |||||||||||||||||||
| 85 | 25 | ▶ | my $args = Str->check( $_[0] ) ? undef : shift; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 25 | push @extends, $class; | |||||||||||||||||||
| 87 | 25 | $extends_args{$class} = $args; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | 23 | $self->superclasses( \@extends ); | |||||||||||||||||||
| 90 | 23 | $self->superclass_args( \%extends_args ); | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 23 | return; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 110 | ▶ | sub _build_parents { | ||||||||||||||||||
|
Subroutine
_build_parents: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 96 | 110 | my $self = shift; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 110 | my $extends = $self->superclasses; | |||||||||||||||||||
| 99 | 110 | ▶ | return [] if !@$extends; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | # Load each parent and store its Mite::Class | ||||||||||||||||||||
| 102 | 18 | my @parents; | |||||||||||||||||||
| 103 | 18 | for my $parent_name (@$extends) { | |||||||||||||||||||
| 104 | 23 | push @parents, $self->_get_parent($parent_name); | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 18 | return \@parents; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 103 | ▶ | sub _get_parent { | ||||||||||||||||||
|
Subroutine
_get_parent: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 111 | 103 | my ( $self, $parent_name ) = ( shift, @_ ); | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 103 | my $project = $self->project; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | # See if it's already loaded | ||||||||||||||||||||
| 116 | 103 | my $parent = $project->class($parent_name); | |||||||||||||||||||
| 117 | 103 | ▶ | return $parent if $parent; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | # If not, try to load it | ||||||||||||||||||||
| 120 | 10 | eval "require $parent_name;"; | |||||||||||||||||||
| 121 | 10 | $parent = $project->class($parent_name); | |||||||||||||||||||
| 122 | 10 | ▶ | return $parent if $parent; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 10 | return; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 109 | ▶ | before inject_mite_functions => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||
| 128 | 109 | my ( $self, $file, $arg ) = ( shift, @_ ); | |||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 109 | ▶ | my $requested = sub { $arg->{$_[0]} ? 1 : $arg->{'!'.$_[0]} ? 0 : $arg->{'-all'} ? 1 : $_[1]; }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.5
Branch: 3 branches
| |||||||||||||||||||||
| 131 | 109 | my $defaults = ! $arg->{'!-defaults'}; | |||||||||||||||||||
| 132 | 109 | my $shim = $self->shim_name; | |||||||||||||||||||
| 133 | 109 | my $package = $self->name; | |||||||||||||||||||
| 134 | 109 | ▶ | my $fake_ns = $self->project->can('_module_fakeout_namespace') && $self->project->_module_fakeout_namespace; | ||||||||||||||||||
|
Condition33%1/3
$self->project->can('_module_fakeout_namespace') && $self->project->_module_fakeout_namespace
MC/DC0%0/2
$self->project->can('_module_fakeout_namespace') && $self->project->_module_fakeout_namespace
$self->project->can('_module_fakeout_namespace')
$self->project->_module_fakeout_namespace
Truth table33%1/3
A && B
A= $self->project->can('_module_fakeout_namespace')B= $self->project->_module_fakeout_namespace
| |||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 117 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 109 | ▶ | if ( $requested->( 'extends', $defaults ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 108 | ▶ | *{ $package .'::extends' } = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||
| 141 | 23 | ▶ | return $self->handle_extends_keyword( | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 142 | defined( $fake_ns ) | ||||||||||||||||||||
| 143 | ? map Str->check($_) ? "$fake_ns\::$_" : $_, @_ | ||||||||||||||||||||
| 144 | : @_ | ||||||||||||||||||||
| 145 | ); | ||||||||||||||||||||
| 146 | 108 | }; | |||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 108 | $self->imported_keywords->{'extends'} = 'sub {}'; | |||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | 117 | }; | |||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 118 | ▶ | around compilation_stages => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 153 | 118 | my ( $next, $self ) = ( shift, shift ); | |||||||||||||||||||
| 154 | 118 | my @stages = $self->$next( @_ ); | |||||||||||||||||||
| 155 | 118 | push @stages, qw( _compile_extends ); | |||||||||||||||||||
| 156 | 118 | return @stages; | |||||||||||||||||||
| 157 | 117 | }; | |||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 118 | ▶ | around _compile_meta_method => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 160 | 118 | my ( $next, $self ) = ( shift, shift ); | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | # Check if we are inheriting from a Mite class in this project | ||||||||||||||||||||
| 163 | 118 | my $inherit_from_mite = do { | |||||||||||||||||||
| 164 | # First parent | ||||||||||||||||||||
| 165 | 118 | my $first_isa = do { | |||||||||||||||||||
| 166 | 118 | my @isa = $self->linear_isa; | |||||||||||||||||||
| 167 | 118 | shift @isa; | |||||||||||||||||||
| 168 | 118 | shift @isa; | |||||||||||||||||||
| 169 | }; | ||||||||||||||||||||
| 170 | 118 | ▶ | !! ( $first_isa and $self->_get_parent( $first_isa ) ); | ||||||||||||||||||
|
Condition100%3/3
$first_isa && $self->_get_parent($first_isa)
MC/DC100%2/2
$first_isa && $self->_get_parent($first_isa)
$first_isa
$self->_get_parent($first_isa)
Truth table100%3/3
A && B
A= $first_isaB= $self->_get_parent($first_isa)
| |||||||||||||||||||||
| 171 | }; | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 118 | ▶ | return '' if $inherit_from_mite; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | 94 | return $self->$next( @_ ); | |||||||||||||||||||
| 176 | 117 | }; | |||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | 118 | ▶ | sub _compile_extends { | ||||||||||||||||||
|
Subroutine
_compile_extends: called CC=4 SCAR=14.2
| |||||||||||||||||||||
| 179 | 118 | my $self = shift; | |||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | 118 | my $extends = $self->superclasses; | |||||||||||||||||||
| 182 | 118 | ▶ | return '' unless @$extends; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | 26 | my $source = $self->source; | |||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | my $require_list = join "\n\t", | ||||||||||||||||||||
| 187 | 9 | map { "require $_;" } | |||||||||||||||||||
| 188 | # Don't require a class from the same source | ||||||||||||||||||||
| 189 | 26 | ▶ | grep { !$source || !$source->has_class($_) } | ||||||||||||||||||
|
Condition66%2/3
$source && $source->has_class($_)
MC/DC50%1/2
$source && $source->has_class($_)
$source
$source->has_class($_)
Truth table66%2/3
A && B
A= $sourceB= $source->has_class($_)
| |||||||||||||||||||||
| 190 | @$extends; | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | my $version_tests = join "\n\t", | ||||||||||||||||||||
| 193 | map { sprintf '%s->VERSION( %s );', | ||||||||||||||||||||
| 194 | B::perlstring( $_ ), | ||||||||||||||||||||
| 195 | 0 | B::perlstring( $self->superclass_args->{$_}{'-version'} ) | |||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | grep { | ||||||||||||||||||||
| 198 | 26 | $self->superclass_args->{$_} | |||||||||||||||||||
| 199 | 29 | ▶ | and $self->superclass_args->{$_}{'-version'} | ||||||||||||||||||
|
Condition33%1/3
$self->superclass_args->{$_} && $self->superclass_args->{$_}{'-version'}
MC/DC0%0/2
$self->superclass_args->{$_} && $self->superclass_args->{$_}{'-version'}
$self->superclass_args->{$_}
$self->superclass_args->{$_}{'-version'}
Truth table33%1/3
A && B
A= $self->superclass_args->{$_}B= $self->superclass_args->{$_}{'-version'}
| |||||||||||||||||||||
| 200 | } | ||||||||||||||||||||
| 201 | @$extends; | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | 26 | my $isa_list = join ", ", map B::perlstring($_), @$extends; | |||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | 26 | return <<"END"; | |||||||||||||||||||
| 206 | BEGIN { | ||||||||||||||||||||
| 207 | $require_list | ||||||||||||||||||||
| 208 | $version_tests | ||||||||||||||||||||
| 209 | use mro 'c3'; | ||||||||||||||||||||
| 210 | our \@ISA; | ||||||||||||||||||||
| 211 | push \@ISA, $isa_list; | ||||||||||||||||||||
| 212 | } | ||||||||||||||||||||
| 213 | END | ||||||||||||||||||||
| 214 | } | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | 0 | ▶ | around _compile_mop_postamble => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 217 | 0 | my ( $next, $self ) = ( shift, shift ); | |||||||||||||||||||
| 218 | 0 | my $code = $self->$next( @_ ); | |||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | 0 | ▶ | my @superclasses = @{ $self->superclasses || [] } | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->superclasses || []
MC/DC0%0/1
$self->superclasses || []
$self->superclasses
Truth table0%0/2
A
A= $self->superclasses
| |||||||||||||||||||||
| 221 | or return $code; | ||||||||||||||||||||
| 222 | 0 | $code .= sprintf "Moose::Util::find_meta( %s )->superclasses( %s );\n", | |||||||||||||||||||
| 223 | B::perlstring( $self->name ), | ||||||||||||||||||||
| 224 | join q{, }, map B::perlstring( $_ ), @superclasses; | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | 0 | return $code; | |||||||||||||||||||
| 227 | 117 | }; | |||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | 117 | 1; | |||||||||||||||||||