line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Yath::Util; |
2
|
1
|
|
|
1
|
|
136782
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.001007'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp qw/confess/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
10
|
1
|
|
|
1
|
|
5
|
use Cwd qw/realpath/; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
33
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
234
|
use Test2::Harness::Util qw/open_file/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
26
|
use Importer Importer => 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw{ |
17
|
|
|
|
|
|
|
load_command |
18
|
|
|
|
|
|
|
find_yath |
19
|
|
|
|
|
|
|
find_pfile |
20
|
|
|
|
|
|
|
PFILE_NAME |
21
|
|
|
|
|
|
|
find_in_updir |
22
|
|
|
|
|
|
|
read_config |
23
|
|
|
|
|
|
|
is_generated_test_pl |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub load_command { |
27
|
0
|
|
|
0
|
0
|
|
my ($cmd_name) = @_; |
28
|
0
|
|
|
|
|
|
my $cmd_class = "App::Yath::Command::$cmd_name"; |
29
|
0
|
|
|
|
|
|
my $cmd_file = "App/Yath/Command/$cmd_name.pm"; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
if (!eval { require $cmd_file; 1 }) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
0
|
|
0
|
|
|
|
my $load_error = $@ || 'unknown error'; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
die "yath command '$cmd_name' not found. (did you forget to install $cmd_class?)\n" |
35
|
|
|
|
|
|
|
if $load_error =~ m{Can't locate \Q$cmd_file\E in \@INC}; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
die $load_error; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $cmd_class; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
0
|
|
sub find_yath { File::Spec->rel2abs(_find_yath()) } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _find_yath { |
46
|
0
|
0
|
|
0
|
|
|
return $App::Yath::SCRIPT if $App::Yath::SCRIPT; |
47
|
0
|
0
|
|
|
|
|
return $ENV{YATH_SCRIPT} if $ENV{YATH_SCRIPT}; |
48
|
0
|
0
|
0
|
|
|
|
return $0 if $0 && $0 =~ m{yath$} && -f $0; |
|
|
|
0
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
require IPC::Cmd; |
51
|
0
|
0
|
|
|
|
|
if(my $out = IPC::Cmd::can_run('yath')) { |
52
|
0
|
|
|
|
|
|
return $out; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
die "Could not find 'yath' in execution path"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub find_in_updir { |
59
|
0
|
|
|
0
|
0
|
|
my $path = shift; |
60
|
0
|
0
|
|
|
|
|
return File::Spec->rel2abs($path) if -f $path; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my %seen; |
63
|
0
|
|
|
|
|
|
while(1) { |
64
|
0
|
|
|
|
|
|
$path = File::Spec->catdir('..', $path); |
65
|
0
|
|
|
|
|
|
my $check = realpath(File::Spec->rel2abs($path)); |
66
|
0
|
0
|
|
|
|
|
last if $seen{$check}++; |
67
|
0
|
0
|
|
|
|
|
return $check if -f $check; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub PFILE_NAME() { '.yath-persist.json' } |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub find_pfile { |
76
|
0
|
|
|
0
|
0
|
|
return find_in_updir(PFILE_NAME()); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub read_config { |
80
|
0
|
|
|
0
|
0
|
|
my ($cmd, $rcfile) = @_; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
0
|
|
|
|
$rcfile ||= find_in_updir('.yath.rc') or return; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $fh = open_file($rcfile, '<'); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my @out; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $in_cmd = 0; |
89
|
0
|
|
|
|
|
|
while (my $line = <$fh>) { |
90
|
0
|
|
|
|
|
|
chomp($line); |
91
|
0
|
0
|
|
|
|
|
if ($line =~ m/^\[(.*)\]$/) { |
92
|
0
|
|
|
|
|
|
$in_cmd = $1 eq $cmd; |
93
|
0
|
|
|
|
|
|
next; |
94
|
|
|
|
|
|
|
} |
95
|
0
|
0
|
|
|
|
|
next unless $in_cmd; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$line =~ s/;.*$//g; |
98
|
0
|
|
|
|
|
|
$line =~ s/^\s*//g; |
99
|
0
|
|
|
|
|
|
$line =~ s/\s*$//g; |
100
|
0
|
|
|
|
|
|
push @out => split /\s+/, $line, 2; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
return @out; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub is_generated_test_pl { |
107
|
0
|
|
|
0
|
0
|
|
my ($file) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $fh = open_file($file, '<'); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $count = 0; |
112
|
0
|
|
|
|
|
|
while (my $line = <$fh>) { |
113
|
0
|
0
|
|
|
|
|
last if $count++ > 5; |
114
|
0
|
0
|
|
|
|
|
next unless $line =~ m/^# THIS IS A GENERATED YATH RUNNER TEST$/; |
115
|
0
|
|
|
|
|
|
return 1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return 0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |