blib/lib/App/hopen/AppUtil.pm

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