File Coverage

blib/lib/Banal/Utils/Class.pm
Criterion Covered Total %
statement 9 31 29.0
branch 0 16 0.0
condition 0 8 0.0
subroutine 3 4 75.0
pod 1 1 100.0
total 13 60 21.6


line stmt bran cond sub pod time code
1             #===============================================
2             package Banal::Utils::Class;
3              
4 1     1   1225 use utf8;
  1         2  
  1         11  
5             require Exporter;
6 1     1   39 no warnings;
  1         3  
  1         35  
7              
8 1     1   7 use Carp;
  1         2  
  1         516  
9              
10             @ISA = qw(Exporter);
11             @EXPORT_OK = qw( load_class);
12              
13              
14             ##############################################################################"
15             # Utility functions
16             ##############################################################################"
17              
18              
19             #----------------------------------
20             # Function, not a method!
21             #----------------------------------
22             sub load_class {
23 0     0 1   my $oclass = shift;
24 0   0       my $prefixes = shift || [''];
25 0   0       my $opts = shift || {};
26            
27 0   0       my $verbose = $opts->{verbose} || 0;
28 0   0       my $on_fail = $opts->{on_fail} || 'warn';
29              
30 0           my $class;
31            
32 0           foreach my $pfx (@$prefixes) {
33 0           $class = $pfx . $oclass;
34 0 0         if (eval "require ($class);") {
35 0           warn "load_class => Just required class '$class'\n";
36 0           return $class;
37             } else {
38 0 0         if ($verbose >= 6) {
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 0         if ($on_fail) {
47 0           my $msg = "load_class => Unable to load(require) class '$oclass'\n";
48            
49 0 0         print STDERR $msg if ($on_fail =~ /^print$/i);
50 0 0         warn $msg if ($on_fail =~ /^warn$/i);
51 0 0         die $msg if ($on_fail =~ /^die$/i);
52 0 0         croak $msg if ($on_fail =~ /^croak$/i);
53 0 0         clutch $msg if ($on_fail =~ /^clutch$/i);
54             }
55            
56            
57 0           return;
58             }
59              
60              
61              
62              
63              
64             1;
65              
66              
67             __END__