| 1 | 115 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 115 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 115 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | package Mite::Source; | ||||||||||||
| 6 | 115 | ▶ | use Mite::Miteception -all; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 115 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||
| 9 | 115 | our $VERSION = '0.013000'; | |||||||||||
| 10 | |||||||||||||
| 11 | 115 | has file => | |||||||||||
| 12 | is => ro, | ||||||||||||
| 13 | isa => Path, | ||||||||||||
| 14 | coerce => true, | ||||||||||||
| 15 | required => true; | ||||||||||||
| 16 | |||||||||||||
| 17 | has classes => | ||||||||||||
| 18 | is => ro, | ||||||||||||
| 19 | isa => HashRef[MiteClass], | ||||||||||||
| 20 | 124 | ▶ | default => sub { {} }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | |||||||||||||
| 22 | has class_order => | ||||||||||||
| 23 | is => ro, | ||||||||||||
| 24 | isa => ArrayRef[NonEmptyStr], | ||||||||||||
| 25 | 124 | ▶ | default => sub { [] }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | |||||||||||||
| 27 | has compiled => | ||||||||||||
| 28 | is => ro, | ||||||||||||
| 29 | isa => MiteCompiled, | ||||||||||||
| 30 | lazy => true, | ||||||||||||
| 31 | 96 | ▶ | default => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 96 | my $self = shift; | |||||||||||
| 33 | 96 | return Mite::Compiled->new( source => $self ); | |||||||||||
| 34 | 115 | }; | |||||||||||
| 35 | |||||||||||||
| 36 | 115 | has project => | |||||||||||
| 37 | is => rw, | ||||||||||||
| 38 | isa => MiteProject, | ||||||||||||
| 39 | # avoid a circular dep with Mite::Project | ||||||||||||
| 40 | weak_ref => true; | ||||||||||||
| 41 | |||||||||||||
| 42 | 115 | ▶ | use Mite::Compiled; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | 115 | ▶ | use Mite::Class; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | |||||||||||||
| 45 | 46 | ▶ | sub has_class { | ||||||||||
|
Subroutine
has_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 46 | 46 | my ( $self, $name ) = ( shift, @_ ); | |||||||||||
| 47 | |||||||||||||
| 48 | 46 | return defined $self->classes->{$name}; | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | 0 | ▶ | sub compile { | ||||||||||
|
Subroutine
compile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||
| 53 | |||||||||||||
| 54 | 0 | return $self->compiled->compile(); | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | # Add an existing class instance to this source | ||||||||||||
| 58 | 1 | ▶ | sub add_classes { | ||||||||||
|
Subroutine
add_classes: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 59 | 1 | my ( $self, @classes ) = ( shift, @_ ); | |||||||||||
| 60 | |||||||||||||
| 61 | 1 | for my $class (@classes) { | |||||||||||
| 62 | 2 | $class->source($self); | |||||||||||
| 63 | |||||||||||||
| 64 | 2 | ▶ | next if $self->classes->{$class->name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 2 | $self->classes->{$class->name} = $class; | |||||||||||
| 66 | 2 | push @{ $self->class_order }, $class->name; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 1 | return; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | # Create or reuse a class instance for this source give a name | ||||||||||||
| 73 | 156 | ▶ | sub class_for { | ||||||||||
|
Subroutine
class_for: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 74 | 156 | my ( $self, $name, $metaclass ) = ( shift, @_ ); | |||||||||||
| 75 | 156 | ▶ | $metaclass ||= 'Mite::Class'; | ||||||||||
|
Condition100%2/2
$metaclass ||= "Mite::Class"
MC/DC100%1/1
$metaclass ||= "Mite::Class"
$metaclass
Truth table100%2/2
A
A= $metaclass
| |||||||||||||
| 76 | |||||||||||||
| 77 | 156 | ▶ | if ( not $self->classes->{$name} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | 152 | eval "require $metaclass"; | |||||||||||
| 79 | 152 | $self->classes->{$name} = $metaclass->new( | |||||||||||
| 80 | name => $name, | ||||||||||||
| 81 | source => $self, | ||||||||||||
| 82 | ); | ||||||||||||
| 83 | 152 | push @{ $self->class_order }, $name; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 156 | return $self->classes->{$name}; | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 0 | ▶ | sub _compile_mop { | ||||||||||
|
Subroutine
_compile_mop: not called CC=2 SCAR=17.9
| |||||||||||||
| 90 | 0 | my ( $self, $name ) = @_; | |||||||||||
| 91 | |||||||||||||
| 92 | my $joined = join "\n", | ||||||||||||
| 93 | 0 | map { $self->classes->{$_}->_compile_mop } | |||||||||||
| 94 | 0 | @{ $self->class_order }; | |||||||||||
| 95 | |||||||||||||
| 96 | 0 | ▶ | while ( $joined =~ /\n\n/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | 0 | $joined =~ s/\n\n/\n/g; | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | 0 | return sprintf <<'CODE', B::perlstring( "$name" ), $joined; | |||||||||||
| 101 | require %s; | ||||||||||||
| 102 | |||||||||||||
| 103 | %s | ||||||||||||
| 104 | CODE | ||||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | 115 | 1; | |||||||||||