blib/lib/Zed/Plugin.pm

filter: Statementstmt 46.8% 15 / 32 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 4 totaltotal 19.5% 19 / 97 CC 15 SCAR 40.5
CC
15
Cov
21%
invoke
110.0
help
30.0
plugins
6.0
CRAP 57.6
« blib/lib/Zed/Range/Parser.pm ↑ Summary blib/lib/Zed/Output.pm »
1 package Zed::Plugin;
2  
3 =head1 NAME
4  
5 Zed::Plugin - Zed plugin management.
6  
7 =head1 SYNOPSIS
8  
9 package Zed::Plugin::Sys::Echo;
10
11 use Zed::Plugin;
12
13 =head1 SYNOPSIS
14
15 Echo some string just for testing plugin
16 ex:
17 echo foo bar
18
19 =cut
20  
21 invoke "echo" => sub { #function invoke
22 print for @_;
23 print "\n";
24  
25 }, sub{ qw(foo foo1 foo2) }; #matchs parameter
26
27 1
28  
29 =cut
30  
31 1 ▶use base Exporter; our @EXPORT = qw(invoke after_invoke);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use Zed::Output;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use Pod::Find qw(pod_where);
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 1 my( %plugins, %invoke, %complete_first );
38  
39 0 ▶sub plugins{ wantarray ? %plugins : {%plugins} }
Subroutine plugins: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
40 0 ▶sub complete_first{ $complete_first{ $_[0] } }
Subroutine complete_first: not called CC=1 SCAR=6.9
Pod undocumented
41  
42 sub help
43 {
44 0 ▶ my $cmd = shift;
Subroutine help: not called CC=5 SCAR=34.0
Pod undocumented
45 0 ▶ info("$cmd not defined") and return unless $plugins{invoke}->{$cmd};
Branch: 1 branch
BranchTrueFalseTotal
unless $plugins{"invoke"}{$cmd} 0 0 0
Condition0%0/5
$plugins{'invoke'}{$cmd} || info("$cmd not defined") && (return)
l!l&&r!l&&!r
000
info("$cmd not defined") and return
!ll
00
MC/DC0%0/2
$plugins{'invoke'}{$cmd} || info("$cmd not defined") && (return)
$plugins{'invoke'}{$cmd} info("$cmd not defined")
Truth table0%0/3
A || B
A= $plugins{'invoke'}{$cmd}B= info("$cmd not defined")
ABresult
1X1
011
000
46  
47 0 my $pod = pod_where({-inc => 1}, $plugins{invoke}->{$cmd});
48 0 ▶ info("$cmd do not have pod") and return unless $pod;
Branch: 1 branch
BranchTrueFalseTotal
unless $pod 0 0 0
Condition0%0/5
$pod || info("$cmd do not have pod") && (return)
l!l&&r!l&&!r
000
info("$cmd do not have pod") and return
!ll
00
MC/DC0%0/2
$pod || info("$cmd do not have pod") && (return)
$pod info("$cmd do not have pod")
Truth table0%0/3
A || B
A= $podB= info("$cmd do not have pod")
ABresult
1X1
011
000
49  
50 0 Pod::Usage::pod2usage( -input => $pod, -output => \*STDERR, -verbose => 0, -exitval => 'NOEXIT' );
51 }
52  
53 sub invoke
54 {
55 0 ▶ my( $cmd, $sub, $complete_first ) = @_;
Subroutine invoke: not called CC=10 SCAR=47.0
Pod undocumented
56 0 ▶ return $invoke{$cmd} if $cmd && !$sub;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd and not $sub 0 0 0
Condition0%0/3
$cmd and not $sub
!ll&&!rl&&r
000
MC/DC0%0/2
$cmd and not $sub
$cmd not $sub
Truth table0%0/3
A and not(B)
A= $cmdB= not $sub
ABresult
0X0
100
111
57  
58 0 my $des = "invoke plugin(cmd: $cmd)";
59 0 my($package, $filename, $line) = caller;
60  
61 0 ▶ warn "load $des from $package failed\n" and return
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd and $sub and ref $sub eq "CODE" 0 0 0
Condition0%0/11
$cmd && $sub && ref $sub eq 'CODE' || warn("load $des from $package failed\n") && (return)
l!l&&r!l&&!r
000
$cmd and $sub and ref $sub eq "CODE"
!ll&&!rl&&r
000
$cmd and $sub
!ll&&!rl&&r
000
warn "load $des from $package failed\n" and return
!ll
00
MC/DC0%0/4
$cmd && $sub && ref $sub eq 'CODE' || warn("load $des from $package failed\n") && (return)
$cmd $sub ref $sub eq "CODE" warn "load $des from $package failed\n"
Truth table0%0/7
A and B and C || D
A= $cmdB= $subC= ref $sub eq "CODE"D= warn "load $des from $package failed\n"
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
62 unless $cmd && $sub
63 && ref $sub eq 'CODE';
64  
65 0 ▶ warn "redefine $des in $package\n" if $invoke{ $cmd };
Branch: 1 branch
BranchTrueFalseTotal
if $invoke{$cmd} 0 0 0
66  
67 0 $invoke{ $cmd } = $sub;
68  
69 0 ▶ $complete_first{ $cmd } = $complete_first
Branch: 1 branch
BranchTrueFalseTotal
if $complete_first and ref $complete_first eq "CODE" 0 0 0
Condition0%0/3
$complete_first and ref $complete_first eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$complete_first and ref $complete_first eq "CODE"
$complete_first ref $complete_first eq "CODE"
Truth table0%0/3
A and B
A= $complete_firstB= ref $complete_first eq "CODE"
ABresult
0X0
100
111
70 if $complete_first && ref $complete_first eq 'CODE';
71  
72 0 $plugins{invoke}->{$cmd} = $package;
73  
74 0 debug( "load $des from $package suc" );
75 }
76  
77  
78 1 1;
« blib/lib/Zed/Range/Parser.pm ↑ Summary blib/lib/Zed/Output.pm »