blib/lib/FindApp/Object/Behavior/Shortcuts.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 92 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package FindApp::Object::Behavior::Shortcuts;
2  
3 use v5.10;
4 use strict;
5 use warnings;
6 use mro "c3";
7  
8 use FindApp::Vars qw(:all);
9 use FindApp::Utils qw(:all);
10  
11 use namespace::clean;
12  
13 my @_SUBDIRS = +BLM;
14 my @_ALLDIRS = (root => @_SUBDIRS);
15  
16 for my $DIR (@_ALLDIRS) {
17 # BUILD: export_bin_to_env
18 # BUIOD: export_lib_to_env
19 # BUIOD: export_man_to_env
20 # BUIOD: export_root_to_env
21 function "export_${DIR}_to_env" => sub { &ENTER_TRACE;
22 my $self = &myself;
23 good_args(@_ == 0);
24 $self->group($DIR)->export_to_env;
25 };
26 # BUILD: bindirs libdirs mandirs rootdirs
27 function "${DIR}dirs" => sub {
28 my $self = &myself;
29 good_args(@_ == 0);
30 my $group = $self->group($DIR);
31 return wantarray ? $group->found : $group;
32 };
33 *rootdir = *rootdir = \&rootdirs;
34  
35 my $is_pl = $DIR ne "root";
36 my $NAMEDIR = $DIR . "dir" . ($is_pl && "s");
37 my $has_have = $is_pl ? "have" : "has";
38 my $is_are = $is_pl ? "are" : "is";
39  
40 my %access_verb = (
41 wanted => $has_have,
42 allowed => $is_are,
43 );
44  
45 while (my($ACCESSOR, $VERB) = each %access_verb) {
46 function $NAMEDIR . "_" . $VERB => sub {
47 my $self = &myself;
48 my $action = join("_" => (@_ ? "set" : "get"), $NAMEDIR, $ACCESSOR);
49 $self->$action(@_);
50 };
51 }
52  
53 } ## for my @DIR (@_ALLDIRS)
54  
55 my @ACCESSORS = qw(allowed found wanted);
56  
57 for my $TYPE (@ACCESSORS) {
58 # BUILD: allowed found wanted
59 function $TYPE => sub {
60 my $self = &myself;
61 good_args(@_ == 1);
62 my $dir = shift;
63 return $self->group($dir)->$TYPE;
64 };
65  
66 for my $DIR (@_ALLDIRS) {
67 my $is_pl = $DIR ne "root";
68 my $NAMEDIR = $DIR . "dir" . ($is_pl && "s");
69  
70 my $ACTION = $NAMEDIR . "_" . $TYPE;
71  
72 # BUILD: <{rootdir,{bin,lib,man}dirs}_{allowed,found,wanted}>
73 # BUILD: rootdir_allowed rootdir_found rootdir_wanted
74 # BUILD: bindirs_allowed bindirs_found bindirs_wanted
75 # BUILD: libdirs_allowed libdirs_found libdirs_wanted
76 # BUILD: mandirs_allowed mandirs_found mandirs_wanted
77 function $ACTION => sub {
78 my $self = &myself;
79 good_args(@_ == 0);
80 return $self->group($DIR)->$TYPE;
81 };
82  
83 for my $OP (qw(add get set)) {
84 my $FUNC_NAME = "${OP}_${ACTION}";
85 # BUILD: <{add,get,set}_{rootdir,{bin,lib,man}dirs}_{allowed,found,wanted}>
86 # BUILD: add_rootdir_allowed add_rootdir_found add_rootdir_wanted
87 # BUILD: add_bindirs_allowed add_bindirs_found add_bindirs_wanted
88 # BUILD: add_libdirs_allowed add_libdirs_found add_libdirs_wanted
89 # BUILD: add_mandirs_allowed add_mandirs_found add_mandirs_wanted
90 # BUILD: get_rootdir_allowed get_rootdir_found get_rootdir_wanted
91 # BUILD: get_bindirs_allowed get_bindirs_found get_bindirs_wanted
92 # BUILD: get_libdirs_allowed get_libdirs_found get_libdirs_wanted
93 # BUILD: get_mandirs_allowed get_mandirs_found get_mandirs_wanted
94 # BUILD: set_rootdir_allowed set_rootdir_found set_rootdir_wanted
95 # BUILD: set_bindirs_allowed set_bindirs_found set_bindirs_wanted
96 # BUILD: set_libdirs_allowed set_libdirs_found set_libdirs_wanted
97 # BUILD: set_mandirs_allowed set_mandirs_found set_mandirs_wanted
98 function $FUNC_NAME => sub {
99 my $self = &myself;
100 croak("$FUNC_NAME: no args allowed") if @_ && $OP eq "get";
101 return $self->group($DIR)->$TYPE->$OP(@_);
102 };
103 } ## for my $OP (qw(add get set))
104  
105 } ## for my @DIR (@_ALLDIRS)
106 } ## for my $TYPE (@ACCESSORS)
107  
108 1;
109  
110 __END__