Phrasebook/Loader.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 90.0% 9 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 96.7% 60 / 62 CC 8 SCAR 16.1
CC
8
Cov
96%
new
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.0
« Phrasebook.pm ↑ Summary Phrasebook/Generic.pm »
1 package Data::Phrasebook::Loader;
2 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use base qw( Data::Phrasebook::Debug );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use Module::Pluggable search_path => ['Data::Phrasebook::Loader'];
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 $VERSION = '0.35';
11  
12 =head1 NAME
13  
14 Data::Phrasebook::Loader - Plugin Loader module
15  
16 =head1 SYNOPSIS
17  
18 my $loader = Data::Phrasebook::Loader->new( class => 'Text' );
19  
20 =head1 DESCRIPTION
21  
22 C<Data::Phrasebook::Loader> acts as an autoloader for phrasebook plugins.
23  
24 =head1 CONSTRUCTOR
25  
26 =head2 new
27  
28 C<new> takes one optional named argument: the class. It returns a new
29 instance to the class. Any further arguments to C<new> are given to
30 the C<new> method of the appropriate class.
31  
32 If no class is specified the default class of 'Text' is used.
33  
34 my $loader = Data::Phrasebook::Loader->new();
35  
36 OR
37  
38 my $loader = Data::Phrasebook::Loader->new( class => 'Text' );
39  
40 =cut
41  
42 12 my $DEFAULT_CLASS = 'Text';
43  
44 27 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
45 27 my $self = shift;
46 27 my %args = @_;
47 27 ▶ my $class = delete $args{class} || 'Text';
Condition100%2/2
delete $args{'class'} || 'Text'
l!l
261
MC/DC100%1/1
delete $args{'class'} || 'Text'
delete $args{'class'}
Truth table100%2/2
A
A= delete $args{'class'}
Aresult
11
00
48  
49 27 ▶ if($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 1 26 27
50 1 $self->store(3,"$self->new IN");
51 1 $self->store(4,"$self->new class=[$class]");
52 }
53  
54 # in the event we have been subclassed
55 27 $self->search_path( add => "$self" );
56  
57 27 my $plugin;
58 27 my @plugins = $self->plugins();
59 27 for(@plugins) {
60 60 ▶ $plugin = $_ if($_ =~ /\b$class$/);
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /\b$class$/ 26 34 60
61 }
62  
63 27 ▶ croak("no loader available of that name\n") unless($plugin);
Branch: 1 branch
BranchTrueFalseTotal
unless $plugin 1 26 27
64  
65 eval {
66 26 (my $file = $plugin) =~ s|::|/|g;
67 26 require $file . '.pm';
68 26 $plugin->import();
69 26 1;
70 26 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { (my $file = $plugin) =~ s[::][/]g; require $file . '.pm'; $plugin->import; 1 } } or do { croak("Couldn't require $plugin : $@") } 26 0 26
71 0 croak "Couldn't require $plugin : $@";
72 };
73  
74 26 ▶ $self->store(4,"$self->new plugin=[$plugin]") if($self->debug);
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 1 25 26
75 26 return $plugin->new( %args );
76 }
77  
78 12 1;
79  
80 __END__
« Phrasebook.pm ↑ Summary Phrasebook/Generic.pm »