| 1 | package FindApp::Object::State; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 6 | ▶ | use v5.10; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 6 | ▶ | use mro "c3"; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 6 | ▶ | use FindApp::Utils qw(:all); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 6 | ▶ | use FindApp::Vars qw(:all); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 6 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 6 | subuse "Group"; | |||||||||||||
| 12 | 6 | subuse "Group::State::Dirs"; | |||||||||||||
| 13 | } | ||||||||||||||
| 14 | 6 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | ################################################################ | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | ▶ | sub canonical_subdirs { | ||||||||||||
|
Subroutine
canonical_subdirs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 19 | # There may not be a singleton yet, and if not, we cannot | ||||||||||||||
| 20 | # autogenerate one at this point, since that needs rootdir etc. | ||||||||||||||
| 21 | 0 | ▶ | return +BLM unless defined &rootdir; # FIXME: wrong namespace for &rootdir | ||||||||||||
|
Subroutine
canonical_subdirs: not called CC=2 SCAR=17.9
Pod
documented
Branch: 2 branches
| |||||||||||||||
| 22 | 0 | my $self = &myself; | |||||||||||||
| 23 | 0 | return $self->subgroup_names; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 0 | ▶ | sub exported_envars() { | ||||||||||||
|
Subroutine
exported_envars: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 27 | state $vars = [ | ||||||||||||||
| 28 | qw($Root), | ||||||||||||||
| 29 | 0 | ▶ | subdir_map { map { ('$'.$_, '@'.$_) } ucfirst }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 30 | 0 | ]; | |||||||||||||
| 31 | 0 | return @$vars; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | ################################################################ | ||||||||||||||
| 35 | # Declare object attributes... | ||||||||||||||
| 36 | 6 | ▶ | use pluskeys qw{ | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 37 | ORIGIN | ||||||||||||||
| 38 | DEFAULT | ||||||||||||||
| 39 | GROUPS | ||||||||||||||
| 40 | 6 | }; | |||||||||||||
| 41 | |||||||||||||||
| 42 | # And define their accessors: | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 14 | ▶ | sub allocate_groups { | ||||||||||||
|
Subroutine
allocate_groups: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 45 | 14 | my $self = &myself; | |||||||||||||
| 46 | 14 | ▶ | $$self{+GROUPS} = { alldir_map { $_ => subpackage("Group")->new($_) } }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | # Attribute group: hash mapping directory grouping names to f:o:s:Group objects. | ||||||||||||||
| 50 | 193 | ▶ | sub group { | ||||||||||||
|
Subroutine
group: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 51 | 193 | my $self = &myself; | |||||||||||||
| 52 | 193 | bad_args(@_ > 1); | |||||||||||||
| 53 | 193 | ▶ | if (@_) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 134 | return $$self{+GROUPS}{lc shift}; | |||||||||||||
| 55 | } else { | ||||||||||||||
| 56 | 59 | return $$self{+GROUPS}; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | } | ||||||||||||||
| 59 | |||||||||||||||
| 60 | # All the group names. | ||||||||||||||
| 61 | 4 | ▶ | sub group_names { | ||||||||||||
|
Subroutine
group_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 62 | 4 | my $self = &myself; | |||||||||||||
| 63 | 4 | bad_args(@_ > 0); | |||||||||||||
| 64 | 4 | return keys %{ $self->group }; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | # All the individual groups. | ||||||||||||||
| 68 | 9 | ▶ | sub groups { | ||||||||||||
|
Subroutine
groups: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 69 | 9 | my $self = &myself; | |||||||||||||
| 70 | 9 | bad_args(@_ > 0); | |||||||||||||
| 71 | 9 | return values %{ $self->group }; | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | # Group names excluding root. | ||||||||||||||
| 75 | 18 | ▶ | sub subgroup_names { | ||||||||||||
|
Subroutine
subgroup_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 76 | 18 | my $self = &myself; | |||||||||||||
| 77 | 18 | bad_args(@_ > 0); | |||||||||||||
| 78 | 18 | return sort grep { $_ ne "root" } keys %{ $self->group }; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | # Groups excluding the root group. | ||||||||||||||
| 82 | 14 | ▶ | sub subgroups { | ||||||||||||
|
Subroutine
subgroups: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 83 | 14 | my $self = &myself; | |||||||||||||
| 84 | 14 | bad_args(@_ > 0); | |||||||||||||
| 85 | 14 | return @{ $self->group } | |||||||||||||
| 86 | 14 | { $self->subgroup_names }; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | # Attribute default_origin. | ||||||||||||||
| 90 | 50 | ▶ | sub default_origin { | ||||||||||||
|
Subroutine
default_origin: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||
| 91 | 50 | my $self = &myself; | |||||||||||||
| 92 | 50 | bad_args(@_ > 1); | |||||||||||||
| 93 | 50 | ▶ | if (@_) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | 23 | my($where) = @_; | |||||||||||||
| 95 | 23 | ▶ | $where =~ /^(?:cwd|script)$/ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 96 | || croak "default origin must be either 'cwd' or 'script', not '$where'"; | ||||||||||||||
| 97 | 23 | $$self{+DEFAULT} = $where; | |||||||||||||
| 98 | } | ||||||||||||||
| 99 | 50 | ▶ | return $$self{+DEFAULT} || "script"; | ||||||||||||
|
Condition100%2/2
$self->{'FindApp::Object::State::DEFAULT'} || 'script'
MC/DC100%1/1
$self->{'FindApp::Object::State::DEFAULT'} || 'script'
$self->{'FindApp::Object::State::DEFAULT'}
Truth table100%2/2
A
A= $self->{'FindApp::Object::State::DEFAULT'}
| |||||||||||||||
| 100 | } | ||||||||||||||
| 101 | |||||||||||||||
| 102 | 27 | ▶ | sub has_origin { | ||||||||||||
|
Subroutine
has_origin: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 103 | 27 | my $self = &myself; | |||||||||||||
| 104 | 27 | bad_args(@_ != 0); | |||||||||||||
| 105 | 27 | return defined $$self{+ORIGIN}; | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | |||||||||||||||
| 108 | 0 | ▶ | sub prefers_dot { | ||||||||||||
|
Subroutine
prefers_dot: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 109 | 0 | my $self = &myself; | |||||||||||||
| 110 | 0 | bad_args(@_ != 0); | |||||||||||||
| 111 | 0 | $self->default_origin eq "cwd"; | |||||||||||||
| 112 | } | ||||||||||||||
| 113 | |||||||||||||||
| 114 | # Attribute origin. | ||||||||||||||
| 115 | 18 | ▶ | sub origin { | ||||||||||||
|
Subroutine
origin: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||
| 116 | 18 | my $self = &myself; | |||||||||||||
| 117 | 18 | bad_args(@_ > 1); | |||||||||||||
| 118 | |||||||||||||||
| 119 | 18 | ▶ | if (@_) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 120 | 4 | my $origin = shift; | |||||||||||||
| 121 | 4 | bad_args(!defined $origin); | |||||||||||||
| 122 | 4 | $$self{+ORIGIN} = $origin; | |||||||||||||
| 123 | } | ||||||||||||||
| 124 | elsif (!$self->has_origin) { | ||||||||||||||
| 125 | 14 | ▶ | $$self{+ORIGIN} = $self->default_origin eq "cwd" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 126 | ? getcwd() | ||||||||||||||
| 127 | : $FindBin::Bin; | ||||||||||||||
| 128 | } | ||||||||||||||
| 129 | |||||||||||||||
| 130 | 18 | return $$self{+ORIGIN}; | |||||||||||||
| 131 | } | ||||||||||||||
| 132 | |||||||||||||||
| 133 | 14 | ▶ | sub reset_origin { | ||||||||||||
|
Subroutine
reset_origin: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 134 | 14 | my $self = &myself; | |||||||||||||
| 135 | 14 | bad_args(@_ > 0); | |||||||||||||
| 136 | 14 | my $old_origin = $self->origin; | |||||||||||||
| 137 | 14 | undef $$self{+ORIGIN}; | |||||||||||||
| 138 | 14 | return $old_origin; | |||||||||||||
| 139 | } | ||||||||||||||
| 140 | |||||||||||||||
| 141 | |||||||||||||||
| 142 | # Pseudo-attribute: app_root | ||||||||||||||
| 143 | |||||||||||||||
| 144 | 0 | ▶ | sub has_app_root { | ||||||||||||
|
Subroutine
has_app_root: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 145 | 0 | my $self = &myself; | |||||||||||||
| 146 | 0 | good_args(@_ == 0); | |||||||||||||
| 147 | 0 | return !!$self->rootdir->found->count; | |||||||||||||
| 148 | } | ||||||||||||||
| 149 | |||||||||||||||
| 150 | 4 | ▶ | sub app_root { | ||||||||||||
|
Subroutine
app_root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 151 | 4 | my $self = &myself; | |||||||||||||
| 152 | 4 | good_args(@_ == 0); | |||||||||||||
| 153 | 4 | return $self->rootdir->found->first; | |||||||||||||
| 154 | } | ||||||||||||||
| 155 | |||||||||||||||
| 156 | 6 | 1; | |||||||||||||
| 157 | |||||||||||||||
| 158 | =encoding utf8 | ||||||||||||||
| 159 | |||||||||||||||
| 160 | =head1 NAME | ||||||||||||||
| 161 | |||||||||||||||
| 162 | FindApp::Object::State - FIXME | ||||||||||||||
| 163 | |||||||||||||||
| 164 | =head1 SYNOPSIS | ||||||||||||||
| 165 | |||||||||||||||
| 166 | use FindApp::Object::State; | ||||||||||||||
| 167 | |||||||||||||||
| 168 | =head1 DESCRIPTION | ||||||||||||||
| 169 | |||||||||||||||
| 170 | =head2 Pluskey Attributes | ||||||||||||||
| 171 | |||||||||||||||
| 172 | These are always private; use the methods insteads. | ||||||||||||||
| 173 | |||||||||||||||
| 174 | =over | ||||||||||||||
| 175 | |||||||||||||||
| 176 | =item DEFAULT | ||||||||||||||
| 177 | |||||||||||||||
| 178 | Either "cwd" or "script", | ||||||||||||||
| 179 | |||||||||||||||
| 180 | =item GROUPS | ||||||||||||||
| 181 | |||||||||||||||
| 182 | Ref to hash mapping directory grouping names to L<FindApp:Object:State:Group> objects. | ||||||||||||||
| 183 | |||||||||||||||
| 184 | =item ORIGIN | ||||||||||||||
| 185 | |||||||||||||||
| 186 | Directory to start the search from. If unset, either the working directory or C<$FindBin::Bin> | ||||||||||||||
| 187 | depending on the value of L</DEFAULT>. | ||||||||||||||
| 188 | |||||||||||||||
| 189 | =back | ||||||||||||||
| 190 | |||||||||||||||
| 191 | =head2 Methods | ||||||||||||||
| 192 | |||||||||||||||
| 193 | =over | ||||||||||||||
| 194 | |||||||||||||||
| 195 | =item allocate_groups | ||||||||||||||
| 196 | |||||||||||||||
| 197 | =item app_root | ||||||||||||||
| 198 | |||||||||||||||
| 199 | =item canonical_subdirs | ||||||||||||||
| 200 | |||||||||||||||
| 201 | =item default_origin | ||||||||||||||
| 202 | |||||||||||||||
| 203 | =item exported_envars | ||||||||||||||
| 204 | |||||||||||||||
| 205 | =item group | ||||||||||||||
| 206 | |||||||||||||||
| 207 | =item group_names | ||||||||||||||
| 208 | |||||||||||||||
| 209 | =item groups | ||||||||||||||
| 210 | |||||||||||||||
| 211 | =item has_app_root | ||||||||||||||
| 212 | |||||||||||||||
| 213 | =item has_origin | ||||||||||||||
| 214 | |||||||||||||||
| 215 | =item origin | ||||||||||||||
| 216 | |||||||||||||||
| 217 | =item prefers_dot | ||||||||||||||
| 218 | |||||||||||||||
| 219 | =item reset_origin | ||||||||||||||
| 220 | |||||||||||||||
| 221 | =item subgroups | ||||||||||||||
| 222 | |||||||||||||||
| 223 | =item subgroup_names | ||||||||||||||
| 224 | |||||||||||||||
| 225 | =back | ||||||||||||||
| 226 | |||||||||||||||
| 227 | =head1 EXAMPLES | ||||||||||||||
| 228 | |||||||||||||||
| 229 | =head1 ENVIRONMENT | ||||||||||||||
| 230 | |||||||||||||||
| 231 | =head1 SEE ALSO | ||||||||||||||
| 232 | |||||||||||||||
| 233 | =over | ||||||||||||||
| 234 | |||||||||||||||
| 235 | =item L<FindApp> | ||||||||||||||
| 236 | |||||||||||||||
| 237 | =back | ||||||||||||||
| 238 | |||||||||||||||
| 239 | =head1 CAVEATS AND PROVISOS | ||||||||||||||
| 240 | |||||||||||||||
| 241 | =head1 BUGS AND LIMITATIONS | ||||||||||||||
| 242 | |||||||||||||||
| 243 | =head1 HISTORY | ||||||||||||||
| 244 | |||||||||||||||
| 245 | =head1 AUTHOR | ||||||||||||||
| 246 | |||||||||||||||
| 247 | Tom Christiansen C<< <tchrist@perl.com> >> | ||||||||||||||
| 248 | |||||||||||||||
| 249 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||
| 250 | |||||||||||||||
| 251 | Copyright (c) 2016, Tom Christiansen C<< <tchrist@perl.com> >>. | ||||||||||||||
| 252 | All Rights Reserved. | ||||||||||||||
| 253 | |||||||||||||||
| 254 | This module is free software; you can redistribute it and/or | ||||||||||||||
| 255 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||||||
| 256 | |||||||||||||||
| 257 | =cut | ||||||||||||||
| 258 | |||||||||||||||