| 1 | package Scrappy::Plugin; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 10 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 10 | $Scrappy::Plugin::VERSION = '0.94112090'; | |||||||||||||
| 5 | } | ||||||||||||||
| 6 | |||||||||||||||
| 7 | # load OO System | ||||||||||||||
| 8 | 10 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | # load other libraries | ||||||||||||||
| 11 | 10 | ▶ | use File::Find::Rule; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | # a hash list of installed plugins | ||||||||||||||
| 14 | has registry => ( | ||||||||||||||
| 15 | is => 'ro', | ||||||||||||||
| 16 | isa => 'HashRef', | ||||||||||||||
| 17 | 2 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | # map plugins | ||||||||||||||
| 20 | 2 | my $plugins = {}; | |||||||||||||
| 21 | 2 | my @plugins = @{shift->plugins}; | |||||||||||||
| 22 | 2 | foreach my $plugin (@plugins) { | |||||||||||||
| 23 | 2 | $plugins->{$plugin} = $plugin; | |||||||||||||
| 24 | 2 | $plugins->{lc($plugin)} = $plugin; | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | 2 | return $plugins; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | 10 | ); | |||||||||||||
| 29 | |||||||||||||||
| 30 | # return a list of installed plugins | ||||||||||||||
| 31 | has plugins => ( | ||||||||||||||
| 32 | is => 'ro', | ||||||||||||||
| 33 | isa => 'Any', | ||||||||||||||
| 34 | 2 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||
| 35 | |||||||||||||||
| 36 | 2 | my @plugins = (); | |||||||||||||
| 37 | |||||||||||||||
| 38 | # fix for bug found by Patrick Woo | ||||||||||||||
| 39 | |||||||||||||||
| 40 | #Can't stat /etc/perl/Scrappy/Plugin: No such file or directory | ||||||||||||||
| 41 | #at /usr/share/perl5/File/Find/Rule.pm line 595 | ||||||||||||||
| 42 | #Can't stat /usr/local/lib/perl/5.10.1/Scrappy/Plugin: No such file or directory | ||||||||||||||
| 43 | #at /usr/share/perl5/File/Find/Rule.pm line 595 | ||||||||||||||
| 44 | #Can't stat /usr/lib/perl5/Scrappy/Plugin: No such file or directory | ||||||||||||||
| 45 | #at /usr/share/perl5/File/Find/Rule.pm line 595 | ||||||||||||||
| 46 | #Can't stat /usr/share/perl5/Scrappy/Plugin: No such file or directory | ||||||||||||||
| 47 | #at /usr/share/perl5/File/Find/Rule.pm line 595 | ||||||||||||||
| 48 | #Can't stat /usr/lib/perl/5.10/Scrappy/Plugin: No such file or directory | ||||||||||||||
| 49 | #at /usr/share/perl5/File/Find/Rule.pm line 595 | ||||||||||||||
| 50 | #Can't stat /usr/share/perl/5.10/Scrappy/Plugin: No such file or directory | ||||||||||||||
| 51 | #at /usr/share/perl5/File/Find/Rule.pm line 595 | ||||||||||||||
| 52 | #Can't stat /usr/local/lib/site_perl/Scrappy/Plugin: No such file or directory | ||||||||||||||
| 53 | #at /usr/share/perl5/File/Find/Rule.pm line 595 | ||||||||||||||
| 54 | #Can't stat ./Scrappy/Plugin: No such file or directory | ||||||||||||||
| 55 | #at /usr/share/perl5/File/Find/Rule.pm line 595 | ||||||||||||||
| 56 | |||||||||||||||
| 57 | # ... (IMO) due to analyzing @INC assuming each path has Scrappy in it | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 2 | my $library; | |||||||||||||
| 60 | |||||||||||||||
| 61 | 2 | foreach my $dir (@INC) { | |||||||||||||
| 62 | 4 | ▶ | if (-d "$dir/Scrappy/Plugin") { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | 2 | $library = "$dir/Scrappy/Plugin"; | |||||||||||||
| 64 | 2 | last; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 2 | ▶ | return [] unless $library; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | |||||||||||||||
| 70 | 2 | my @files = File::Find::Rule->file()->name('*.pm')->in($library); | |||||||||||||
| 71 | |||||||||||||||
| 72 | my %plugins = | ||||||||||||||
| 73 | 2 | map { $_ => 1 } | |||||||||||||
| 74 | 2 | map { s/.*(Scrappy[\\\/]Plugin[\\\/].*\.pm)/$1/; $_ } | |||||||||||||
| 75 | @files; #uniquenes | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 2 | for my $plugin (keys %plugins) { | |||||||||||||
| 78 | |||||||||||||||
| 79 | 2 | my ($plug) = $plugin =~ /(Scrappy\/Plugin\/.*)\.pm/; | |||||||||||||
| 80 | |||||||||||||||
| 81 | 2 | ▶ | if ($plug) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 82 | 2 | $plug =~ s/\//::/g; | |||||||||||||
| 83 | 2 | push @plugins, $plug; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | 2 | return [@plugins]; | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | 10 | ); | |||||||||||||
| 91 | |||||||||||||||
| 92 | 0 | ▶ | sub load_plugin { | ||||||||||||
|
Subroutine
load_plugin: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||
| 93 | 0 | my $self = shift; | |||||||||||||
| 94 | 0 | my @plugins = @_; | |||||||||||||
| 95 | 0 | my @returns = (); | |||||||||||||
| 96 | |||||||||||||||
| 97 | 0 | foreach my $plugin (@plugins) { | |||||||||||||
| 98 | |||||||||||||||
| 99 | 0 | ▶ | unless ($plugin =~ /^Scrappy::Plugin::/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 100 | |||||||||||||||
| 101 | # make fully-quaified plugin name | ||||||||||||||
| 102 | 0 | $plugin = ucfirst $plugin; | |||||||||||||
| 103 | |||||||||||||||
| 104 | 0 | ▶ | $plugin = join("::", map(ucfirst, split '-', $plugin)) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | if $plugin =~ /\-/; | ||||||||||||||
| 106 | 0 | ▶ | $plugin = join("", map(ucfirst, split '_', $plugin)) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 107 | if $plugin =~ /\_/; | ||||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | $plugin = "Scrappy::Plugin::$plugin"; | |||||||||||||
| 110 | } | ||||||||||||||
| 111 | |||||||||||||||
| 112 | # check for a direct match | ||||||||||||||
| 113 | 0 | ▶ | if ($self->registry->{$plugin}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 114 | 0 | with $self->registry->{$plugin}; | |||||||||||||
| 115 | 0 | push @returns, $self->registry->{$plugin}; | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | # last resort seek | ||||||||||||||
| 119 | elsif ($self->registry->{lc($plugin)}) { | ||||||||||||||
| 120 | 0 | with $self->registry->{lc($plugin)}; | |||||||||||||
| 121 | 0 | push @returns, $self->registry->{lc($plugin)}; | |||||||||||||
| 122 | } | ||||||||||||||
| 123 | else { | ||||||||||||||
| 124 | 0 | die( "Error loading the plugin $plugin, " | |||||||||||||
| 125 | . "please check that it has been installed"); | ||||||||||||||
| 126 | } | ||||||||||||||
| 127 | } | ||||||||||||||
| 128 | |||||||||||||||
| 129 | 0 | return @returns; | |||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | 10 | 1; | |||||||||||||