| 1 | package AutoCode::ModuleLoader; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use AutoCode::ModuleFactory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | our $SCHEMA; | |||||||||||||||||||||||||||
| 5 | 3 | our $FACTORY; | |||||||||||||||||||||||||||
| 6 | 3 | our %LOADED; # Cache | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # In the previous design, the method 'import' can load any specific type. And | ||||||||||||||||||||||||||||
| 9 | # we forbid the feature, since it cannot return virtual package we want, and | ||||||||||||||||||||||||||||
| 10 | # the users should not guess/predict what the virtual package is, which is the | ||||||||||||||||||||||||||||
| 11 | # internal business to decide the VP of this AutoCode. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 14 | 3 | my $pkg=shift; | |||||||||||||||||||||||||||
| 15 | 3 | ▶ | $pkg->load_schema(@_) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | sub load_schema { | ||||||||||||||||||||||||||
|
Subroutine
load_schema: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 3 | my ($pkg, $schema, $prefix)=@_; | |||||||||||||||||||||||||||
| 20 | 3 | AutoCode::Root->_load_module($schema); | |||||||||||||||||||||||||||
| 21 | 3 | ▶ | my @args = (defined $prefix and $prefix ne 'default') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $prefix and $prefix ne "default"
MC/DC50%1/2
defined $prefix and $prefix ne "default"
defined $prefix
$prefix ne "default"
Truth table66%2/3
A and B
A= defined $prefixB= $prefix ne "default"
| |||||||||||||||||||||||||||||
| 22 | ? (-package_prefix => $prefix):(); | ||||||||||||||||||||||||||||
| 23 | 3 | $SCHEMA= $schema->new(@args); | |||||||||||||||||||||||||||
| 24 | 3 | $FACTORY=AutoCode::ModuleFactory->new( | |||||||||||||||||||||||||||
| 25 | -schema => $SCHEMA | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # Cache is at work. | ||||||||||||||||||||||||||||
| 30 | 4 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 4 | my ($pkg, $type, $prefix)=@_; | |||||||||||||||||||||||||||
| 32 | 4 | ▶ | return $LOADED{$type} if(exists $LOADED{$type}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 4 | my $vp = $FACTORY->make_module($type); | |||||||||||||||||||||||||||
| 34 | 4 | $LOADED{$type}=$vp; | |||||||||||||||||||||||||||
| 35 | 4 | return $vp; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub load_all { | ||||||||||||||||||||||||||
|
Subroutine
load_all: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 0 | my ($pkg)=@_; | |||||||||||||||||||||||||||
| 41 | 0 | my @types=$SCHEMA->get_all_types; | |||||||||||||||||||||||||||
| 42 | 0 | foreach(@types){ | |||||||||||||||||||||||||||
| 43 | 0 | $pkg->load($_); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | 1; | |||||||||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||||||||||