SpellCheck/Plugin/Combo.pm

filter: Statementstmt 90.3% 56 / 62 Branchbran 63.6% 14 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 14.2% 1 / 7 totaltotal 81.1% 86 / 106 CC 19 SCAR 12.3
CC
19
Cov
83%
_plugin
6.9
stopwords
4.0
can
4.0
CRAP 3.4
↑ Summary SpellCheck/Plugin/PerlComment.pm »
1 package Test::SpellCheck::Plugin::Combo;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Module::Load qw( load );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Ref::Util qw( is_plain_arrayref is_blessed_ref is_ref );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our @CARP_NOT = qw( Test::SpellCheck );
12  
13 # ABSTRACT: Test::SpellCheck plugin for combining other plugins.
14 2 our $VERSION = '0.02'; # VERSION
15  
16  
17 30 ▶sub _plugin ($spec)
Subroutine _plugin: called CC=5 SCAR=19.3
18 {
19 30 ▶ if(is_plain_arrayref $spec)
Branch: 3 branches
BranchTrueFalseTotal
if (is_plain_arrayref($spec)) { } 11 19 30
elsif (is_blessed_ref($spec)) { } 19 0 19
elsif (not is_ref($spec)) { } 0 0 0
20 {
21 11 my($class, @args) = @$spec;
22 11 $class = "Test::SpellCheck::Plugin::$class";
23 11 ▶ load $class unless $class->can('new');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can("new") 5 6 11
24 11 return $class->new(@args);
25 }
26 elsif(is_blessed_ref $spec)
27 {
28 19 return $spec;
29 }
30 elsif(!is_ref $spec)
31 {
32 0 my $class = "Test::SpellCheck::Plugin::$spec";
33 0 load $class;
34 0 return $class->new;
35 }
36 else
37 {
38 0 croak "Unknown plugin type: @{[ ref $spec ]}";
39 }
40 }
41  
42  
43 15 ▶sub new ($class, @plugins)
Subroutine new: called CC=1 SCAR=0.0
Pod documented
44 {
45 bless {
46 15 plugins => [ map { _plugin($_) } @plugins ],
47 }, $class;
48 }
49  
50 12 ▶sub can ($self, $name)
Subroutine can: called CC=4 SCAR=13.9
Pod undocumented
51 {
52 12 ▶ if($name eq 'primary_dictionary')
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'primary_dictionary') { } 3 9 12
53 {
54 3 foreach my $plugin ($self->{plugins}->@*)
55 {
56 2 my $maybe = $plugin->can($name);
57 2 ▶ return $maybe if defined $maybe;
Branch: 1 branch
BranchTrueFalseTotal
if defined $maybe 2 0 2
58 }
59 1 return undef;
60 }
61 else
62 {
63 9 return $self->SUPER::can($name);
64 }
65 }
66  
67 3 ▶sub primary_dictionary ($self)
Subroutine primary_dictionary: called CC=3 SCAR=12.7
Pod undocumented
68 {
69 3 foreach my $plugin ($self->{plugins}->@*)
70 {
71 # TODO: make sure we don't have more than one.
72 3 ▶ return $plugin->primary_dictionary if $plugin->can('primary_dictionary');
Branch: 1 branch
BranchTrueFalseTotal
if $plugin->can("primary_dictionary") 3 0 3
73 }
74 0 croak "no primary dictionary for this combo";
75 }
76  
77 2 ▶sub dictionary ($self)
Subroutine dictionary: called CC=3 SCAR=11.1
Pod undocumented
78 {
79 2 my @dic;
80 2 foreach my $plugin ($self->{plugins}->@*)
81 {
82 2 ▶ push @dic, $plugin->dictionary if $plugin->can('dictionary');
Branch: 1 branch
BranchTrueFalseTotal
if $plugin->can("dictionary") 2 0 2
83 }
84 2 return @dic;
85 }
86  
87 2 ▶sub stopwords ($self)
Subroutine stopwords: called CC=4 SCAR=14.0
Pod undocumented
88 {
89 2 my %words;
90 2 foreach my $plugin ($self->{plugins}->@*)
91 {
92 2 ▶ if($plugin->can('stopwords'))
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin->can("stopwords")) 2 0 2
93 {
94 2 $words{$_} = 1 for $plugin->stopwords;
95 }
96 }
97 2 return sort keys %words;
98 }
99  
100 1 ▶sub splitter ($self)
Subroutine splitter: called CC=3 SCAR=11.1
Pod undocumented
101 {
102 1 my @cpu;
103 1 foreach my $plugin ($self->{plugins}->@*)
104 {
105 2 ▶ if($plugin->can('splitter'))
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin->can("splitter")) 2 0 2
106 {
107 2 push @cpu, $plugin->splitter;
108 }
109 }
110 1 return @cpu;
111 }
112  
113 5 ▶sub stream ($self, $filename, $splitter, $callback)
Subroutine stream: called CC=3 SCAR=11.0
Pod undocumented
114 {
115 5 foreach my $plugin ($self->{plugins}->@*)
116 {
117 13 ▶ $plugin->stream($filename, $splitter, $callback) if $plugin->can('stream');
Branch: 1 branch
BranchTrueFalseTotal
if $plugin->can("stream") 7 6 13
118 }
119 5 return $self;
120 }
121  
122 2 1;
123  
124 __END__
↑ Summary SpellCheck/Plugin/PerlComment.pm »