Labyrinth/Plugins.pm

filter: Statementstmt 65.7% 25 / 38 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 56.9% 33 / 58 CC 6 SCAR 25.6
CC
6
Cov
54%
get_plugin
30.0
load_plugins
6.0
get_plugins
2.0
CRAP 13.0
« Labyrinth/MLUtils.pm ↑ Summary Labyrinth/DIUtils/Base.pm »
1 package Labyrinth::Plugins;
2  
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Labyrinth::Plugins - Plugin Manager for Labyrinth
9  
10 =head1 SYNOPSIS
11  
12 load_plugins(@plugins);
13 my $plugin = get_plugin($class);
14 my @plugins = get_plugins();
15  
16 =head1 DESCRIPTION
17  
18 Although loaded via the main Labyrinth module, this module is used by others
19 to quickly reference all the available plugins.
20  
21 =cut
22  
23 12 ▶use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 12 $VERSION = '5.32';
25  
26 # -------------------------------------
27 # Export Details
28  
29 12 require Exporter;
30 12 @ISA = qw(Exporter);
31  
32 12 %EXPORT_TAGS = (
33 'all' => [ qw(load_plugins get_plugin get_plugins) ],
34 );
35  
36 12 @EXPORT_OK = ( @{$EXPORT_TAGS{'all'}} );
37 12 @EXPORT = ( @{$EXPORT_TAGS{'all'}} );
38  
39 # -------------------------------------
40 # Library Modules
41  
42 12 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 12 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 # -------------------------------------
46 # Variables
47  
48 12 my (%plugins,%classes);
49  
50 # -------------------------------------
51 # The Program
52  
53 =head1 FUNCTIONS
54  
55 =over
56  
57 =item load_plugins()
58  
59 Loads plugins found under the plugins directory.
60  
61 =item get_plugin($class)
62  
63 Returns the appropriate plugin for the given class.
64  
65 =item get_plugins()
66  
67 Returns all available plugins.
68  
69 =back
70  
71 =cut
72  
73 0 ▶sub load_plugins {
Subroutine load_plugins: not called CC=2 SCAR=17.9
Pod documented
74 0 $classes{$_} = 1 for(@_);
75 }
76  
77 0 ▶sub get_plugin {
Subroutine get_plugin: not called CC=5 SCAR=34.0
Pod documented
78 0 my $class = shift;
79 0 my $method = 'new';
80
81 0 ▶ return $plugins{$class} if($plugins{$class});
Branch: 1 branch
BranchTrueFalseTotal
if $plugins{$class} 0 0 0
82 0 ▶ return unless($classes{$class});
Branch: 1 branch
BranchTrueFalseTotal
unless $classes{$class} 0 0 0
83  
84 0 eval {
85 0 eval "CORE::require $class";
86 0 $plugins{$class} = $class->$method(@_);
87 };
88  
89 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
90 0 $tvars{errcode} = 'ERROR';
91 0 LogError("action: class=$class, method=new, FAULT: $@");
92 }
93  
94 0 ▶ return $plugins{$class} || undef;
Condition0%0/2
$plugins{$class} || undef
l!l
00
MC/DC0%0/1
$plugins{$class} || undef
$plugins{$class}
Truth table0%0/2
A
A= $plugins{$class}
Aresult
11
00
95 }
96  
97 0 ▶sub get_plugins {
Subroutine get_plugins: not called CC=1 SCAR=6.9
Pod documented
98 0 return values %plugins;
99 }
100  
101 12 1;
102  
103 __END__
« Labyrinth/MLUtils.pm ↑ Summary Labyrinth/DIUtils/Base.pm »