| 1 | #=============================================== | ||||||||||||
| 2 | package Banal::Utils::Class; | ||||||||||||
| 3 | |||||||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | require Exporter; | |||||||||||
| 6 | 2 | ▶ | no warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 2 | @ISA = qw(Exporter); | |||||||||||
| 11 | 2 | @EXPORT_OK = qw( load_class); | |||||||||||
| 12 | |||||||||||||
| 13 | |||||||||||||
| 14 | ##############################################################################" | ||||||||||||
| 15 | # Utility functions | ||||||||||||
| 16 | ##############################################################################" | ||||||||||||
| 17 | |||||||||||||
| 18 | |||||||||||||
| 19 | #---------------------------------- | ||||||||||||
| 20 | # Function, not a method! | ||||||||||||
| 21 | #---------------------------------- | ||||||||||||
| 22 | 0 | ▶ | sub load_class { | ||||||||||
|
Subroutine
load_class: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||
| 23 | 0 | my $oclass = shift; | |||||||||||
| 24 | 0 | ▶ | my $prefixes = shift || ['']; | ||||||||||
|
Condition0%0/2
shift() || ['']
MC/DC0%0/1
shift() || ['']
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 25 | 0 | ▶ | my $opts = shift || {}; | ||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 26 | |||||||||||||
| 27 | 0 | ▶ | my $verbose = $opts->{verbose} || 0; | ||||||||||
|
Condition0%0/2
$opts->{'verbose'} || 0
MC/DC0%0/1
$opts->{'verbose'} || 0
$opts->{'verbose'}
Truth table0%0/2
A
A= $opts->{'verbose'}
| |||||||||||||
| 28 | 0 | ▶ | my $on_fail = $opts->{on_fail} || 'warn'; | ||||||||||
|
Condition0%0/2
$opts->{'on_fail'} || 'warn'
MC/DC0%0/1
$opts->{'on_fail'} || 'warn'
$opts->{'on_fail'}
Truth table0%0/2
A
A= $opts->{'on_fail'}
| |||||||||||||
| 29 | |||||||||||||
| 30 | 0 | my $class; | |||||||||||
| 31 | |||||||||||||
| 32 | 0 | foreach my $pfx (@$prefixes) { | |||||||||||
| 33 | 0 | $class = $pfx . $oclass; | |||||||||||
| 34 | 0 | ▶ | if (eval "require ($class);") { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 0 | warn "load_class => Just required class '$class'\n"; | |||||||||||
| 36 | 0 | return $class; | |||||||||||
| 37 | } else { | ||||||||||||
| 38 | 0 | ▶ | if ($verbose >= 6) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 0 | my $msg = "load_class => Tried to load(require) class '$oclass' via package name '$class' without any luck. Oh well. Next time perhaps.\n"; | |||||||||||
| 40 | |||||||||||||
| 41 | 0 | print STDERR $msg; | |||||||||||
| 42 | } | ||||||||||||
| 43 | } | ||||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 0 | ▶ | if ($on_fail) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 0 | my $msg = "load_class => Unable to load(require) class '$oclass'\n"; | |||||||||||
| 48 | |||||||||||||
| 49 | 0 | ▶ | print STDERR $msg if ($on_fail =~ /^print$/i); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 0 | ▶ | warn $msg if ($on_fail =~ /^warn$/i); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 0 | ▶ | die $msg if ($on_fail =~ /^die$/i); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 0 | ▶ | croak $msg if ($on_fail =~ /^croak$/i); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 0 | ▶ | clutch $msg if ($on_fail =~ /^clutch$/i); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | 0 | return; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | |||||||||||||
| 62 | |||||||||||||
| 63 | |||||||||||||
| 64 | 2 | 1; | |||||||||||
| 65 | |||||||||||||
| 66 | |||||||||||||
| 67 | __END__ | ||||||||||||