blib/lib/Zed.pm

filter: Statementstmt 27.1% 25 / 92 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 57.1% 8 / 14 Podpod 0.0% 0 / 1 totaltotal 18.1% 33 / 182 CC 30 SCAR 45.0
CC
30
Cov
16%
run
210.0
_result
72.0
__ANON__
42.0
CRAP 90.0
↑ Summary blib/lib/Zed/Range/Parser.pm »
1 package Zed;
2  
3 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Term::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Zed::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Zed::Output;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Zed::Config::Env;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Zed::Config::Space;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 our $VERSION = '0.02';
14  
15 sub _macro
16 {
17 0 ▶ my ($text, $stat) = @_;
Subroutine _macro: not called CC=4 SCAR=30.0
18 0 my %plugins = Zed::Plugin::plugins();
19 my %hash =
20 (
21 0 %{ env('macro') },
22 0 map{$_ => $_}keys %{$plugins{invoke}},
23 );
24  
25 0 ▶ if($hash{$text})
Branch: 1 branch
BranchTrueFalseTotal
if ($hash{$text}) 0 0 0
26 {
27 0 ▶ return $hash{$text} if $stat == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $stat == 0 0 0 0
28 0 return ();
29 }
30 0 my @grep = sort grep{ /^$text/ }keys %hash;
31 0 ▶ $grep[$stat] ? $grep[$stat] : ();
Branch: 1 branch
BranchTrueFalseTotal
$grep[$stat] ? : 0 0 0
32 }
33  
34 sub _result
35 {
36 0 ▶ return unless ref $_[0] eq 'ARRAY'
Subroutine _result: not called CC=8 SCAR=42.8
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" and ref $_[1] eq "ARRAY" and scalar @_ >= 2 0 0 0
Condition0%0/6
ref $_[0] eq "ARRAY" and ref $_[1] eq "ARRAY" and scalar @_ >= 2
!ll&&!rl&&r
000
ref $_[0] eq "ARRAY" and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $_[0] eq "ARRAY" and ref $_[1] eq "ARRAY" and scalar @_ >= 2
ref $_[0] eq "ARRAY" ref $_[1] eq "ARRAY" scalar @_ >= 2
Truth table0%0/4
A and B and C
A= ref $_[0] eq "ARRAY"B= ref $_[1] eq "ARRAY"C= scalar @_ >= 2
ABCresult
0XX0
10X0
1100
1111
37 and ref $_[1] eq 'ARRAY'
38 and scalar @_ >= 2;
39  
40 0 my($suc, $fail, $result) = @_;
41  
42 0 ▶ $result ||= {};
Condition0%0/2
$result ||= {}
l!l
00
MC/DC0%0/1
$result ||= {}
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
43  
44 0 my( %group, %content, $count );
45  
46 0 push @{ $content{ $result->{$_} } }, $_ for keys %$result;
47  
48 0 ▶ while(my($text, $host) = each %content)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %content) 0 0 0
49 {
50 0 $count += 1;
51 0 my $group = "group". $count;
52 0 $group{$group} = $host;
53 0 ▶ if(@$host <= 5)
Branch: 1 branch
BranchTrueFalseTotal
if (@$host <= 5) { } 0 0 0
54 {
55 0 info("$group\[", join(',', @$host), "\]:");
56 }else{
57 0 info("$group\[", scalar @$host,"\]:");
58 }
59 0 text($text);
60 }
61  
62 0 env( "result", {space => usespace(), "suc" => $suc, "fail" => $fail, "group" => \%group } );
63 0 info(sprintf "\nsuc:[ %s ], fail:[ %s ]\n", scalar @$suc, scalar @$fail);
64 }
65  
66 sub run
67 {
68 0 ▶ my ($term, $attribs, $prompt) = Term::ReadLine->new(__PACKAGE__);
Subroutine run: not called CC=14 SCAR=53.5
Pod undocumented
69 0 my $hist = File::Spec->join( $ENV{ZED_HOME}, "history" );
70 0 $term->ReadHistory($hist);
71 0 $attribs = $term->Attribs;
72  
73 $attribs->{attempted_completion_function} = sub {
74  
75 0 ▶ my($text, $line, $start, $end) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
76  
77 0 ▶ if( substr($line, 0, $start) =~ /^\s*$/ )
Branch: 2 branches
BranchTrueFalseTotal
if (substr($line, 0, $start) =~ /^\s*$/) { } 0 0 0
elsif ($line =~ /^(\w+) / and $start == 1 + length($1)) { } 0 0 0
78 {
79 0 return $term->completion_matches($text, \&_macro)
80
81 ▶ }elsif( $line =~ /^(\w+) / and $start == 1 + length $1){
Condition0%0/3
$line =~ /^(\w+) / and $start == 1 + length($1)
!ll&&!rl&&r
000
MC/DC0%0/2
$line =~ /^(\w+) / and $start == 1 + length($1)
$line =~ /^(\w+) / $start == 1 + length($1)
Truth table0%0/3
A and B
A= $line =~ /^(\w+) /B= $start == 1 + length($1)
ABresult
0X0
100
111
82  
83 0 my($sub, @word) = Zed::Plugin::complete_first( $1 );
84 0 ▶ return unless $sub and @word = $sub->();
Branch: 1 branch
BranchTrueFalseTotal
unless $sub and @word = &$sub() 0 0 0
Condition0%0/3
$sub and @word = &$sub()
!ll&&!rl&&r
000
MC/DC0%0/2
$sub and @word = &$sub()
$sub @word = &$sub()
Truth table0%0/3
A and B
A= $subB= @word = &$sub()
ABresult
0X0
100
111
85 return $term->completion_matches($text, sub{
86  
87 0 ▶ my ($text, $stat, @grep) = splice @_, 0, 2;
Subroutine __ANON__: not called CC=2 SCAR=17.9
88  
89 0 @grep = sort grep{ /^$text/ } @word;
90 0 ▶ $grep[$stat] ? $grep[$stat] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$grep[$stat] ? : 0 0 0
91 })
92
93 0 }
94 0 return;
95 0 };
96  
97 sigaction SIGINT, new POSIX::SigAction sub {
98 0 ▶ $term->delete_text;
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 $attribs->{point} = $attribs->{end} = 0;
100 0 print "\n", $prompt;
101 0 $|=1;
102 0 ▶ } or die "Error setting SIGINT handler: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
sigaction(2, "POSIX::SigAction"->new(sub { $term->delete_text; $attribs->{"point"} = $attribs->{"end"} = 0; print "\n", $prompt; $| = 1; } )) or die "Error setting SIGINT handler: $!\n" 0 0 0
103  
104 0 while(1)
105 {
106 0 ▶ $prompt = ( env("username")||"nouser" ) . "\@zed#> ";
Condition0%0/2
env('username') || 'nouser'
l!l
00
MC/DC0%0/1
env('username') || 'nouser'
env('username')
Truth table0%0/2
A
A= env('username')
Aresult
11
00
107 0 my $in = $term->readline($prompt);
108 0 ▶ next unless $in; $in =~ s/ *$//;
Branch: 1 branch
BranchTrueFalseTotal
unless $in 0 0 0
109  
110 0 my( $cmd, undef, $param, @params ) = $in =~ /^(.+?)(\s+(.+))?$/;
111 0 ▶ @params = grep{$_} split /\s/, $param if $param;
Branch: 1 branch
BranchTrueFalseTotal
if $param 0 0 0
112 0 ▶ warn "input($in) error\n" and next unless $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 0 0
Condition0%0/5
$cmd || warn("input($in) error\n") && (next)
l!l&&r!l&&!r
000
warn "input($in) error\n" and next
!ll
00
MC/DC0%0/2
$cmd || warn("input($in) error\n") && (next)
$cmd warn "input($in) error\n"
Truth table0%0/3
A || B
A= $cmdB= warn "input($in) error\n"
ABresult
1X1
011
000
113  
114 0 debug("cmd: |$cmd|");
115 0 ▶ debug("param: |$param|") if $param;
Branch: 1 branch
BranchTrueFalseTotal
if $param 0 0 0
116 0 ▶ debug("params:", \@params) if @params;
Branch: 1 branch
BranchTrueFalseTotal
if @params 0 0 0
117  
118 0 ▶ last if $cmd eq 'quit';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "quit" 0 0 0
119  
120 0 my($sub, @return, $after) = invoke($cmd);
121 0 ▶ debug("get invoke:", ref $sub ? "suc" : "faild");
Branch: 1 branch
BranchTrueFalseTotal
ref $sub ? : 0 0 0
122  
123 0 ▶ @return = $sub ? $sub->(@params) : info("no invoke plugin(cmd: $cmd) defined") && next;
Branch: 1 branch
BranchTrueFalseTotal
$sub ? : 0 0 0
Condition0%0/2
info("no invoke plugin(cmd: $cmd) defined") and next
!ll
00
MC/DC0%0/1
info("no invoke plugin(cmd: $cmd) defined") and next
info("no invoke plugin(cmd: $cmd) defined")
Truth table0%0/2
A
A= info("no invoke plugin(cmd: $cmd) defined")
Aresult
00
11
124  
125 0 _result( @return );
126
127 #$term->addhistory($in);
128 }
129 0 ▶ $term->WriteHistory($hist) or warn "cannot write history file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$term->WriteHistory($hist) or warn "cannot write history file: $!\n" 0 0 0
130 }
131 1 1;
132 __END__
↑ Summary blib/lib/Zed/Range/Parser.pm »