| 1 | 19 | ▶ | use 5.010001; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 2 | 19 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 3 | 19 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||
| 5 | package Mite::Role; | ||||||||||||||||||||||||
| 6 | 19 | ▶ | use Mite::Miteception -all; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | 19 | extends qw( | |||||||||||||||||||||||
| 8 | Mite::Package | ||||||||||||||||||||||||
| 9 | ); | ||||||||||||||||||||||||
| 10 | 19 | with qw( | |||||||||||||||||||||||
| 11 | Mite::Trait::HasRequiredMethods | ||||||||||||||||||||||||
| 12 | Mite::Trait::HasAttributes | ||||||||||||||||||||||||
| 13 | Mite::Trait::HasRoles | ||||||||||||||||||||||||
| 14 | Mite::Trait::HasMethods | ||||||||||||||||||||||||
| 15 | Mite::Trait::HasMOP | ||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||
| 18 | 19 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||
| 19 | 19 | our $VERSION = '0.013000'; | |||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||
| 21 | 19 | ▶ | use Path::Tiny; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 22 | 19 | ▶ | use B (); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||
| 24 | 20 | ▶ | sub kind { 'role' } | ||||||||||||||||||||||
|
Subroutine
kind: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||
| 26 | 12 | ▶ | sub methods_to_export { | ||||||||||||||||||||||
|
Subroutine
methods_to_export: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||
| 27 | 12 | my ( $self, $role_args ) = @_; | |||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||
| 29 | 12 | my %methods = %{ $self->methods_to_import_from_roles }; | |||||||||||||||||||||||
| 30 | 12 | my %native = %{ $self->native_methods }; | |||||||||||||||||||||||
| 31 | 12 | my $package = $self->name; | |||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||
| 33 | 12 | for my $name ( keys %native ) { | |||||||||||||||||||||||
| 34 | 10 | $methods{$name} = "$package\::$name"; | |||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||
| 37 | 12 | ▶ | if ( my $excludes = $role_args->{'-excludes'} ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 38 | 1 | ▶ | for my $excluded ( ref( $excludes ) ? @$excludes : $excludes ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 39 | 1 | delete $methods{$excluded}; | |||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | 12 | ▶ | if ( my $alias = $role_args->{'-alias'} ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 44 | 1 | for my $oldname ( sort keys %$alias ) { | |||||||||||||||||||||||
| 45 | 1 | my $newname = $alias->{$oldname}; | |||||||||||||||||||||||
| 46 | 1 | $methods{$newname} = delete $methods{$oldname}; | |||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||
| 50 | 12 | return \%methods; | |||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | 1 | ▶ | sub accessors_to_export { | ||||||||||||||||||||||
|
Subroutine
accessors_to_export: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||
| 54 | 1 | my $self = shift; | |||||||||||||||||||||||
| 55 | 1 | ▶ | return {} unless $self->arg->{'-runtime'}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||
| 57 | my @accessors = map $_->associated_methods, | ||||||||||||||||||||||||
| 58 | 0 | sort { $a->_order <=> $b->_order } | |||||||||||||||||||||||
| 59 | 1 | values %{ $self->attributes }; | |||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||
| 61 | 1 | return { map { $_ => $self->name . "::$_"; } @accessors }; | |||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||
| 64 | 10 | ▶ | around compilation_stages => sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||
| 65 | 10 | my ( $next, $self ) = ( shift, shift ); | |||||||||||||||||||||||
| 66 | 10 | my @stages = $self->$next( @_ ); | |||||||||||||||||||||||
| 67 | 10 | push @stages, qw( | |||||||||||||||||||||||
| 68 | _compile_callback | ||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||
| 70 | push @stages, '_compile_runtime_application' | ||||||||||||||||||||||||
| 71 | 10 | ▶ | if $self->arg->{'-runtime'}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 72 | 10 | return @stages; | |||||||||||||||||||||||
| 73 | 19 | }; | |||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||
| 75 | 1 | ▶ | sub _compile_runtime_application { | ||||||||||||||||||||||
|
Subroutine
_compile_runtime_application: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||
| 76 | 1 | my $self = shift; | |||||||||||||||||||||||
| 77 | 1 | my $name = $self->name; | |||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||
| 79 | my $methods = { | ||||||||||||||||||||||||
| 80 | 1 | %{ $self->methods_to_export }, | |||||||||||||||||||||||
| 81 | 1 | %{ $self->accessors_to_export }, | |||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||
| 83 | my $method_hash = join qq{,\n}, | ||||||||||||||||||||||||
| 84 | map sprintf( | ||||||||||||||||||||||||
| 85 | ' %s => %s', | ||||||||||||||||||||||||
| 86 | B::perlstring( $_ ), | ||||||||||||||||||||||||
| 87 | 1 | ▶ | B::perlstring( $methods->{$_} =~ /^\Q$name\E::(\w+)$/ ? $1 : $methods->{$_} ) | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 88 | ), | ||||||||||||||||||||||||
| 89 | sort keys %$methods; | ||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||
| 91 | 1 | return sprintf <<'CODE', $method_hash; | |||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||
| 93 | our ( %%METHODS ) = ( | ||||||||||||||||||||||||
| 94 | %s | ||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||
| 97 | my %%DONE; | ||||||||||||||||||||||||
| 98 | sub APPLY_TO { | ||||||||||||||||||||||||
| 99 | my $to = shift; | ||||||||||||||||||||||||
| 100 | if ( ref $to ) { | ||||||||||||||||||||||||
| 101 | my $new_class = CREATE_CLASS( ref $to ); | ||||||||||||||||||||||||
| 102 | return bless( $to, $new_class ); | ||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||
| 104 | return if $DONE{$to}; | ||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||
| 106 | no strict 'refs'; | ||||||||||||||||||||||||
| 107 | ${"$to\::USES_MITE"} = 'Mite::Class'; | ||||||||||||||||||||||||
| 108 | for my $method ( keys %%METHODS ) { | ||||||||||||||||||||||||
| 109 | $to->can($method) or *{"$to\::$method"} = \&{ $METHODS{$method} }; | ||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||
| 111 | for ( "DOES", "does" ) { | ||||||||||||||||||||||||
| 112 | $to->can( $_ ) or *{"$to\::$_"} = sub { shift->isa( @_ ) }; | ||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||
| 115 | __PACKAGE__->__FINALIZE_APPLICATION__( $to ); | ||||||||||||||||||||||||
| 116 | $MITE_SHIM->HANDLE_around( $to, "class", [ "DOES", "does" ], sub { | ||||||||||||||||||||||||
| 117 | my ( $next, $self, $role ) = @_; | ||||||||||||||||||||||||
| 118 | return 1 if $role eq __PACKAGE__; | ||||||||||||||||||||||||
| 119 | return 1 if $role eq $to; | ||||||||||||||||||||||||
| 120 | return $self->$next( $role ); | ||||||||||||||||||||||||
| 121 | } ); | ||||||||||||||||||||||||
| 122 | $DONE{$to}++; | ||||||||||||||||||||||||
| 123 | return; | ||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||
| 126 | sub CREATE_CLASS { | ||||||||||||||||||||||||
| 127 | my $base = shift; | ||||||||||||||||||||||||
| 128 | my $new_class = "$base\::__WITH__::" . __PACKAGE__; | ||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||
| 130 | no strict 'refs'; | ||||||||||||||||||||||||
| 131 | @{"$new_class\::ISA"} = $base; | ||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||
| 133 | APPLY_TO( $new_class ); | ||||||||||||||||||||||||
| 134 | return $new_class; | ||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||
| 137 | CODE | ||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||
| 140 | 10 | ▶ | sub _compile_callback { | ||||||||||||||||||||||
|
Subroutine
_compile_callback: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||
| 141 | 10 | my $self = shift; | |||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||
| 143 | 10 | my @required = @{ $self->required_methods }; | |||||||||||||||||||||||
| 144 | 10 | my %uniq; undef $uniq{$_} for @required; | |||||||||||||||||||||||
| 145 | 10 | @required = sort keys %uniq; | |||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||
| 147 | 10 | my $role_list = join q[, ], map B::perlstring( $_->name ), @{ $self->roles }; | |||||||||||||||||||||||
| 148 | my $shim = B::perlstring( | ||||||||||||||||||||||||
| 149 | $self->shim_name | ||||||||||||||||||||||||
| 150 | 0 | ▶ | || eval { $self->project->config->data->{shim} } | ||||||||||||||||||||||
|
Condition40%2/5
$self->shim_name || eval {
do {
$self->project->config->data->{'shim'}
}
} || 'Mite::Shim'
$self->shim_name or eval {
do {
$self->project->config->data->{"shim"}
}
}
MC/DC0%0/2
$self->shim_name || eval {
do {
$self->project->config->data->{'shim'}
}
} || 'Mite::Shim'
$self->shim_name
eval {
do {
$self->project->config->data->{"shim"}
}
}
Truth table33%1/3
A or B
A= $self->shim_nameB= eval {
do {
$self->project->config->data->{"shim"}
}
}
| |||||||||||||||||||||||||
| 151 | || 'Mite::Shim' | ||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||
| 153 | 10 | my $croak = $self->_function_for_croak; | |||||||||||||||||||||||
| 154 | 10 | my $missing_methods = '()'; | |||||||||||||||||||||||
| 155 | 10 | ▶ | if ( @required ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 156 | 2 | require B; | |||||||||||||||||||||||
| 157 | 2 | $missing_methods = sprintf 'grep( !$target->can($_), %s )', | |||||||||||||||||||||||
| 158 | join q[, ], map B::perlstring( $_ ), @required; | ||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||
| 161 | 10 | return sprintf <<'CODE', $missing_methods, $croak, $role_list, $croak, $shim; | |||||||||||||||||||||||
| 162 | # Callback which classes consuming this role will call | ||||||||||||||||||||||||
| 163 | sub __FINALIZE_APPLICATION__ { | ||||||||||||||||||||||||
| 164 | my ( $me, $target, $args ) = @_; | ||||||||||||||||||||||||
| 165 | our ( %%CONSUMERS, @METHOD_MODIFIERS ); | ||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||
| 167 | # Ensure a given target only consumes this role once. | ||||||||||||||||||||||||
| 168 | if ( exists $CONSUMERS{$target} ) { | ||||||||||||||||||||||||
| 169 | return; | ||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||
| 171 | $CONSUMERS{$target} = 1; | ||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||
| 173 | my $type = do { no strict 'refs'; ${"$target\::USES_MITE"} }; | ||||||||||||||||||||||||
| 174 | return if $type ne 'Mite::Class'; | ||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||
| 176 | my @missing_methods; | ||||||||||||||||||||||||
| 177 | @missing_methods = %s | ||||||||||||||||||||||||
| 178 | and %s( "$me requires $target to implement methods: " . join q[, ], @missing_methods ); | ||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||
| 180 | my @roles = ( %s ); | ||||||||||||||||||||||||
| 181 | my %%nextargs = %%{ $args || {} }; | ||||||||||||||||||||||||
| 182 | ( $nextargs{-indirect} ||= 0 )++; | ||||||||||||||||||||||||
| 183 | %s( "PANIC!" ) if $nextargs{-indirect} > 100; | ||||||||||||||||||||||||
| 184 | for my $role ( @roles ) { | ||||||||||||||||||||||||
| 185 | $role->__FINALIZE_APPLICATION__( $target, { %%nextargs } ); | ||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||
| 188 | my $shim = %s; | ||||||||||||||||||||||||
| 189 | for my $modifier_rule ( @METHOD_MODIFIERS ) { | ||||||||||||||||||||||||
| 190 | my ( $modification, $names, $coderef ) = @$modifier_rule; | ||||||||||||||||||||||||
| 191 | my $handler = "HANDLE_$modification"; | ||||||||||||||||||||||||
| 192 | $shim->$handler( $target, "class", $names, $coderef ); | ||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||
| 195 | return; | ||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||
| 197 | CODE | ||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||
| 200 | 10 | ▶ | sub _needs_accessors { | ||||||||||||||||||||||
|
Subroutine
_needs_accessors: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||
| 201 | 10 | my $self = shift; | |||||||||||||||||||||||
| 202 | 10 | ▶ | $self->arg->{'-runtime'} ? true : false; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||
| 205 | 0 | ▶ | sub _mop_metaclass { | ||||||||||||||||||||||
|
Subroutine
_mop_metaclass: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 206 | 0 | return '$META_ROLE'; | |||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||
| 209 | 0 | ▶ | sub _mop_attribute_metaclass { | ||||||||||||||||||||||
|
Subroutine
_mop_attribute_metaclass: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 210 | 0 | return 'Moose::Meta::Role::Attribute'; | |||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||
| 213 | 0 | ▶ | sub _compile_mop_modifiers { | ||||||||||||||||||||||
|
Subroutine
_compile_mop_modifiers: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 214 | 0 | my $self = shift; | |||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||
| 216 | 0 | return sprintf <<'CODE', $self->name; | |||||||||||||||||||||||
| 217 | for ( @%s::METHOD_MODIFIERS ) { | ||||||||||||||||||||||||
| 218 | my ( $type, $names, $code ) = @$_; | ||||||||||||||||||||||||
| 219 | $PACKAGE->${\"add_$type\_method_modifier"}( $_, $code ) for @$names; | ||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||
| 221 | CODE | ||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||
| 224 | 0 | ▶ | sub _compile_mop_tc { | ||||||||||||||||||||||
|
Subroutine
_compile_mop_tc: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 225 | 0 | return sprintf ' Moose::Util::TypeConstraints::find_or_create_does_type_constraint( %s );', | |||||||||||||||||||||||
| 226 | B::perlstring( shift->name ); | ||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||
| 229 | 19 | 1; | |||||||||||||||||||||||