| 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.01'; | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return $hash{$text} if $stat == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my @grep = sort grep{ /^$text/ }keys %hash; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $grep[$stat] ? $grep[$stat] : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
ref $_[0] eq "ARRAY" and ref $_[1] eq "ARRAY" and scalar @_ >= 2
ref $_[0] eq "ARRAY" and ref $_[1] eq "ARRAY"
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 ||= {}
MC/DC0%0/1
$result ||= {}
$result
Truth table0%0/2
A
A= $result
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $count += 1; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $group = "group". $count; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $group{$group} = $host; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if(@$host <= 5) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my($sub, @word) = Zed::Plugin::complete_first( $1 ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return unless $sub and @word = $sub->(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sub and @word = &$sub()
MC/DC0%0/2
$sub and @word = &$sub()
$sub
@word = &$sub()
Truth table0%0/3
A and B
A= $subB= @word = &$sub()
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | while(1) | |||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $prompt = ( env("username")||"nouser" ) . "\@zed#> "; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
env('username') || 'nouser'
MC/DC0%0/1
env('username') || 'nouser'
env('username')
Truth table0%0/2
A
A= env('username')
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $in = $term->readline($prompt); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | next unless $in; $in =~ s/ *$//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my( $cmd, undef, $param, @params ) = $in =~ /^(.+?)(\s+(.+))?$/; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | @params = grep{$_} split /\s/, $param if $param; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | warn "input($in) error\n" and next unless $cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$cmd || warn("input($in) error\n") && (next)
warn "input($in) error\n" and next
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | debug("cmd: |$cmd|"); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | debug("param: |$param|") if $param; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | debug("params:", \@params) if @params; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | last if $cmd eq 'quit'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my($sub, @return, $after) = invoke($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | debug("get invoke:", ref $sub ? "suc" : "faild"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | @return = $sub ? $sub->(@params) : info("no invoke plugin(cmd: $cmd) defined") && next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
info("no invoke plugin(cmd: $cmd) defined") and next
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||||||||||||||||