PJVM/ClassLoader.pm

filter: Statementstmt 100% 46 / 46 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 91.5% 65 / 71 CC 8 SCAR 10.6
CC
8
Cov
95%
load_class
5.0
new
4.0
BEGIN
1.0
CRAP 2.9
« PJVM/Class/Attribute/LocalVariableTable.pm ↑ Summary PJVM/Class/ConstantPool.pm »
1 package PJVM::ClassLoader;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use File::Slurp qw(slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use IO::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use PJVM::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 our @ISA = qw(Exporter);
14  
15 3 ▶use Object::Tiny qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
16 classpath
17 3 );
18  
19 4 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod undocumented
20 4 my ($pkg, $args) = @_;
21
22 4 ▶ $args = {} unless ref $args eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 0 4 4
23
24 4 my $classpath;
25 4 ▶ if ($args->{classpath}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"classpath"}) 4 0 4
26 4 ▶ die "argument 'classpath' must be an array reference" unless ref $args->{classpath} eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args->{"classpath"} eq "ARRAY" 1 3 4
27 3 $classpath = $args->{classpath};
28 }
29
30 3 my $self = bless {
31 classpath => $classpath,
32 }, $pkg;
33
34 3 return $self;
35 }
36  
37 4 ▶sub load_class {
Subroutine load_class: called CC=5 SCAR=16.1
Pod undocumented
38 4 my ($self, $fqcn) = @_;
39
40 # Find the class to load
41 4 my $path;
42 4 for my $cp (@{$self->classpath}) {
43 4 my $pt = File::Spec->catfile($cp, "${fqcn}.class");
44 4 ▶ if (-e $pt) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $pt) 3 1 4
45 3 $path = $pt;
46 3 last;
47 }
48 }
49
50 4 ▶ die "Can't find '${fqcn}.class' in my classpath" unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 1 3 4
51
52 3 ▶ open(my $io, "<:raw", $path) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $io, "<:raw", $path or die $! 3 0 3
53 3 my $class = $self->read_class($io);
54 3 close($io);
55
56 3 return $class;
57 }
58  
59 3 ▶sub read_class {
Subroutine read_class: called CC=1 SCAR=0.0
Pod undocumented
60 3 my ($self, $io) = @_;
61 3 return PJVM::Class->new_from_io($io);
62 }
63  
64 3 1;
65 __END__
« PJVM/Class/Attribute/LocalVariableTable.pm ↑ Summary PJVM/Class/ConstantPool.pm »