| 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
| |||||||||||
| 23 | |||||||||||
| 24 | 4 | my $classpath; | |||||||||
| 25 | 4 | ▶ | if ($args->{classpath}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 4 | ▶ | die "argument 'classpath' must be an array reference" unless ref $args->{classpath} eq "ARRAY"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 51 | |||||||||||
| 52 | 3 | ▶ | open(my $io, "<:raw", $path) || die $!; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||