Hopen/AppUtil.pm

filter: Statementstmt 84.3% 43 / 51 Branchbran 27.2% 6 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 64.2% 9 / 14 Podpod 100% 2 / 2 totaltotal 64.8% 61 / 94 CC 13 SCAR 19.3
CC
13
Cov
66%
find_myhopen
20.0
find_hopen_files
9.6
__ANON__
6.0
CRAP 6.9
« Hopen.pm ↑ Summary Hopen/Scope/Hash.pm »
1 # Build::Hopen::AppUtil - utility routines used by Build::Hopen::App
2 package Build::Hopen::AppUtil;
3 1 ▶use Build::Hopen qw(:default isMYH MYH);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Build::Hopen::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.000008'; # TRIAL
8  
9 1 our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
10 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 @EXPORT = qw();
12 1 @EXPORT_OK = qw(find_hopen_files find_myhopen);
13 1 %EXPORT_TAGS = (
14 default => [@EXPORT],
15 all => [@EXPORT, @EXPORT_OK]
16 );
17 }
18  
19 1 ▶use Cwd qw(getcwd abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use File::Glob $] lt '5.016' ? ':glob' : ':bsd_glob';
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$] lt '5.016' ? : 0 1 1
21 # Thanks to haukex, https://www.perlmonks.org/?node_id=1207115 -
22 # 5.14 doesn't support the ':bsd_glob' tag.
23 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # Docs {{{1
26  
27 =head1 NAME
28  
29 Build::Hopen::AppUtil - utility routines used by Build::Hopen::App
30  
31 =head1 FUNCTIONS
32  
33 # }}}1
34  
35 =head2 find_hopen_files
36  
37 Find the hopen files applicable to the given build directory.
38 Returns a list of hopen files, if any, to process for the given directory.
39 Hopen files match C<*.hopen.pl> or C<.hopen.pl>. Usage:
40 Also locates context files. For example, when processing C<~/foo/.hopen>,
41 Check will also find C<~/foo.hopen> if it exists.
42  
43 my $files_array = find_hopen_files(
44 [$proj_dir[, $dest_dir[, $ignore_MY_hopen]]])
45  
46 If no C<$proj_dir> is given, the current directory is used.
47  
48 If C<$ignore_MY_hopen> is truthy, C<$dest_dir> will not be checked for
49 a C<MY.hopen.pl> file.
50  
51 The returned files should be processed in left-to-right order.
52  
53 The return array will include a context file if any is present.
54 For C<$dir eq '/foo/bar'>, for example, C</foo/bar.hopen.pl> is the
55 name of the context file.
56  
57 =cut
58  
59 1 ▶sub find_hopen_files {
Subroutine find_hopen_files: called CC=7 SCAR=22.6
Pod documented
60 1 ▶ my $proj_dir = @_ ? dir($_[0]) : dir;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
61 1 ▶ my $dest_dir = dir($_[1]) if @_>=2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 2 0 1 1
62 1 my $ignore_MY_hopen = $_[2];
63  
64 1 ▶ local *d = sub { $proj_dir->file(shift) };
Subroutine __ANON__: called CC=1 SCAR=0.0
65  
66 0 ▶ hlog { 'Looking for hopen files in', $proj_dir->absolute };
Subroutine __ANON__: not called CC=1 SCAR=1.2
67  
68 # Look for files that are included with the project
69 my @candidates = sort(
70 1 ▶ grep { !isMYH && -r } (
Condition33%1/3
!isMYH() && -r $_
!ll&&!rl&&r
002
MC/DC0%0/2
!isMYH() && -r $_
!isMYH() -r $_
Truth table33%1/3
not(A) && B
A= !isMYH()B= -r $_
ABresult
0X0
100
111
71 bsd_glob(d('*.hopen.pl'), GLOB_NOSORT),
72 bsd_glob(d('.hopen.pl'), GLOB_NOSORT),
73 )
74 );
75 0 ▶ hlog { 'Candidates:', @candidates ? @candidates : 'none' };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
@candidates ? : 0 0 0
76 1 ▶ @candidates = $candidates[$#candidates] if @candidates;
Branch: 1 branch
BranchTrueFalseTotal
if @candidates 1 0 1
77 # Only use the last one
78  
79 # Look in the parent dir for context files.
80 # The context file comes after the earlier candidate.
81 1 my $parent = $proj_dir->parent;
82 1 ▶ if($parent ne $proj_dir) { # E.g., not root dir
Branch: 1 branch
BranchTrueFalseTotal
if ($parent ne $proj_dir) 1 0 1
83 1 my $me = $proj_dir->absolute->basename;
84 # Absolute because dir might be `.`.
85 1 my $context_file = $parent->file("$me.hopen.pl");
86 1 ▶ if(-r $context_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $context_file) 1 0 1
87 1 push @candidates, $context_file;
88 0 ▶ hlog { 'Context file', $context_file };
Subroutine __ANON__: not called CC=1 SCAR=1.2
89 }
90 }
91  
92 0 ▶ hlog { @candidates ? ('Using hopen files', @candidates) :
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
@candidates ? : 0 0 0
93 1 'No hopen files found on disk' };
94 1 return [@candidates];
95 } #find_hopen_files()
96  
97 =head2 find_myhopen
98  
99 Find a C<MY.hopen.pl> file, if any. Returns undef if none is present.
100  
101 =cut
102  
103 0 ▶sub find_myhopen {
Subroutine find_myhopen: not called CC=4 SCAR=30.0
Pod documented
104 0 ▶ return if $_[1]; # $ignore_MY_hopen
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 0 0 0
105 0 ▶ my $dest_dir = shift or return; # No dest dir => no MY.hopen.pl
Branch: 1 branch
BranchTrueFalseTotal
my $dest_dir = shift() or return 0 0 0
106  
107 # Find $dest_dir/MY.hopen.pl, if there is one.
108 0 my $fn = $dest_dir->file(MYH);
109 0 ▶ return $fn if -r $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -r $fn 0 0 0
110 } #find_myhopen
111  
112 1 1;
113 __END__
« Hopen.pm ↑ Summary Hopen/Scope/Hash.pm »