Wrangler/PluginManager.pm

filter: Statementstmt 18.5% 10 / 54 Branchbran 0.0% 0 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 28.5% 2 / 7 Podpod 0.0% 0 / 5 totaltotal 12.0% 12 / 100 CC 23 SCAR 51.0
CC
23
Cov
11%
load_plugins
272.0
plugins
56.0
disable_plugin
6.0
CRAP 164.2
« Wrangler/Config.pm ↑ Summary Wrangler/Wx/FileBrowser.pm »
1 package Wrangler::PluginManager;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our @plugins;
7 1 our $phase_plugins;
8 1 our %enabled;
9 0 ▶sub load_plugins {
Subroutine load_plugins: not called CC=16 SCAR=56.1
Pod undocumented
10 0 my $wrangler = shift;
11 0 ▶ die 'Wrangler::PluginManager has a functional interface but needs the $wrangler obj for plugins' unless $wrangler;
Branch: 1 branch
BranchTrueFalseTotal
unless $wrangler 0 0 0
12  
13 0 my %seen = ();
14 # this is modeled after Padre::PluginManager::load_plugins
15 0 foreach my $inc (@INC) {
16 0 my $dir = File::Spec->catdir( $inc, 'Wrangler', 'Plugin' );
17 0 ▶ next unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
18  
19 0 Wrangler::debug("Wrangler::PluginManager::load_plugins: readdir $dir");
20 0 ▶ opendir(my $dirh, $dir) or die "Wrangler::PluginManager::load_plugins: opendir $dir failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dirh, $dir or die "Wrangler::PluginManager::load_plugins: opendir $dir failed: $!" 0 0 0
21 0 ▶ my @files = readdir($dirh) or die "Wrangler::PluginManager::load_plugins: readdir $dir failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
my(@files) = readdir $dirh or die "Wrangler::PluginManager::load_plugins: readdir $dir failed: $!" 0 0 0
22 0 ▶ closedir($dirh) or die "Wrangler::PluginManager::load_plugins: closedir $dir failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
closedir $dirh or die "Wrangler::PluginManager::load_plugins: closedir $dir failed: $!" 0 0 0
23  
24 0 foreach (@files) {
25 0 ▶ next unless s/\.pm$//;
Branch: 1 branch
BranchTrueFalseTotal
unless s/\.pm$// 0 0 0
26 0 my $module = "Wrangler::Plugin::$_";
27 0 ▶ next if $seen{$module}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$module}++ 0 0 0
28  
29 0 Wrangler::debug("Wrangler::PluginManager::load_plugins: module:$module in $dir");
30 0 eval "use $module ();";
31 0 ▶ Wrangler::debug(" eval 'use' module failed:\n $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
32  
33 # Wrangler::debug(' version: '. ${ $module . '::VERSION' }) if ${ $module . '::VERSION' };
34  
35 0 ▶ next unless $module->can('plugin_phases');
Branch: 1 branch
BranchTrueFalseTotal
unless $module->can("plugin_phases") 0 0 0
36  
37 0 ▶ my $plugin = $module->new($wrangler) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $plugin = $module->new($wrangler) or next 0 0 0
38  
39 0 ▶ next unless ref($plugin) =~ /^Wrangler::Plugin::/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref($plugin) =~ /^Wrangler::Plugin::/ 0 0 0
40  
41 0 push(@plugins,$plugin);
42 }
43 }
44  
45 # call plugins for phase "wrangler_startup"
46 0 ▶ if( my $plugins_ref = Wrangler::PluginManager::plugins('wrangler_startup') ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $plugins_ref = plugins("wrangler_startup")) 0 0 0
47 0 for my $plugin (@$plugins_ref){
48 # print "PluginManager::load_plugins and call startup: $plugin\n";
49 0 $plugin->wrangler_startup();
50 }
51 }
52 }
53  
54 # loading plugin simply prepares the obj, by calling new, which shouldn't do much
55 # plugs then are actually 'enabled' later on, by calling enable_plugin(), which
56 # calls the Plugin's enable_plugin and pushes the pos into @enabled
57 0 ▶sub enable_plugin {
Subroutine enable_plugin: not called CC=1 SCAR=6.9
Pod undocumented
58 0 Wrangler::debug("Enable Plugin '$_[0]'");
59 0 $enabled{$_[0]} = 1;
60 0 $Wrangler::Config::settings{'plugins'}{$_[0]} = 1;
61 0 return 1;
62 }
63 0 ▶sub disable_plugin {
Subroutine disable_plugin: not called CC=2 SCAR=17.9
Pod undocumented
64 0 ▶ return 0 unless defined($Wrangler::Config::settings{'plugins'}{$_[0]});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Wrangler::Config::settings{"plugins"}{$_[0]} 0 0 0
65 0 Wrangler::debug("Disable Plugin '$_[0]'");
66 0 $Wrangler::Config::settings{'plugins'}{$_[0]} = 0;
67 0 return 1;
68 }
69 0 ▶sub is_enabled {
Subroutine is_enabled: not called CC=1 SCAR=6.9
Pod undocumented
70 # Wrangler::debug("PluginManager::is_enabled: @_");
71 0 return $Wrangler::Config::settings{'plugins'}{$_[0]};
72 }
73  
74  
75 0 ▶sub plugins {
Subroutine plugins: not called CC=7 SCAR=40.3
Pod undocumented
76 0 my $phase = shift;
77  
78 0 ▶ return unless $Wrangler::Config::settings{'plugins'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Wrangler::Config::settings{"plugins"} 0 0 0
79  
80 0 ▶ return \@plugins unless $phase;
Branch: 1 branch
BranchTrueFalseTotal
unless $phase 0 0 0
81  
82 # in case we got a phase, return only plugins for this phase
83 0 ▶ unless($phase_plugins){
Branch: 1 branch
BranchTrueFalseTotal
unless ($Wrangler::PluginManager::phase_plugins) 0 0 0
84 0 for(@plugins){
85 0 ▶ next unless $Wrangler::Config::settings{'plugins'}{ $_->plugin_name };
Branch: 1 branch
BranchTrueFalseTotal
unless $Wrangler::Config::settings{"plugins"}{$_->plugin_name} 0 0 0
86 0 for my $phase (keys %{ $_->plugin_phases() }){
87 0 push(@{ $phase_plugins->{$phase} }, $_);
88 }
89 }
90 # require Data::Dumper;
91 # Wrangler::debug("Done building optimisation hash:".Data::Dumper::Dumper(\@plugins, $phase_plugins));
92 }
93  
94 0 return $phase_plugins->{$phase};
95 }
96  
97 1 1;
« Wrangler/Config.pm ↑ Summary Wrangler/Wx/FileBrowser.pm »