| 1 | package FindApp::Object::State::Group::Behavior; | ||||||||||||||||||||||||||||
| 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::Vars qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use FindApp::Utils qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | #use Env qw(@PATH); | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub bin2man() { | ||||||||||||||||||||||||||||
| 13 | my(@manpath, %seen); | ||||||||||||||||||||||||||||
| 14 | for my $bindir (@PATH) { | ||||||||||||||||||||||||||||
| 15 | next if $bindir =~ /^[.]{0,2}\z/; | ||||||||||||||||||||||||||||
| 16 | my $parent = dirname($bindir); | ||||||||||||||||||||||||||||
| 17 | for my $mandir (map "$parent/$_", qw(man share/man)) { | ||||||||||||||||||||||||||||
| 18 | next if $seen{$mandir}++; | ||||||||||||||||||||||||||||
| 19 | next unless -d $mandir; | ||||||||||||||||||||||||||||
| 20 | my($dev, $ino) = stat _; | ||||||||||||||||||||||||||||
| 21 | next if $seen{$dev, $ino}++; | ||||||||||||||||||||||||||||
| 22 | push @manpath, $mandir; | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | return @manpath; | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 6 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 18 | ▶ | sub base_has_wanteds { &ENTER_TRACE_2; | ||||||||||||||||||||||||||
|
Subroutine
base_has_wanteds: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 18 | good_args(@_ == 2); | |||||||||||||||||||||||||||
| 32 | 18 | my($self, $base) = @_; | |||||||||||||||||||||||||||
| 33 | # alloweds are always dirs, so tack on a trailing slash | ||||||||||||||||||||||||||||
| 34 | my @have = $self->allowed->count | ||||||||||||||||||||||||||||
| 35 | 18 | ▶ | ? grep { -e } map { "$base/$_" } $self->allowed | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | : $base; | ||||||||||||||||||||||||||||
| 37 | # Can we find everthing we want in what we have? | ||||||||||||||||||||||||||||
| 38 | 18 | ▶ | for my $want (map { /^\w+(::\w+)+$/ ? module2path : $_ } $self->wanted) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 8 | my $found; | |||||||||||||||||||||||||||
| 40 | 8 | for my $have (@have) { | |||||||||||||||||||||||||||
| 41 | 8 | ▶ | if ($found = -e "$have/$want") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 6 | debug "found $have/$want"; | |||||||||||||||||||||||||||
| 43 | 6 | last; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 8 | ▶ | return unless $found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 16 | $self->found(map { abs_path } @have); | |||||||||||||||||||||||||||
| 49 | 16 | return 1; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 16 | ▶ | sub expected_name { | ||||||||||||||||||||||||||
|
Subroutine
expected_name: called CC=2 SCAR=9.7
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | good_args(@_ == 2); | ||||||||||||||||||||||||||
|
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my($self, $want_name) = @_; | |||||||||||||||||||||||||||
| 55 | 16 | my $have_name = $self->name; | |||||||||||||||||||||||||||
| 56 | 16 | ▶ | unless ($have_name eq $want_name) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 57 | 0 | panic "group $have_name is not a $want_name group"; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 16 | ▶ | sub export_to_env { &ENTER_TRACE_2; | ||||||||||||||||||||||||||
|
Subroutine
export_to_env: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | 16 | my $exporter = "export_" . $self->name . "_to_env"; | |||||||||||||||||||||||||||
| 64 | 16 | $self->$exporter; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 4 | ▶ | sub export_root_to_env { &ENTER_TRACE_2; | ||||||||||||||||||||||||||
|
Subroutine
export_root_to_env: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | 4 | $self->expected_name("root"); | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($self->have_exported) { debug "already exported root to env" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 4 | ($APP_ROOT) = $self->found; | |||||||||||||||||||||||||||
| 72 | 4 | debug("\$APP_ROOT = '$APP_ROOT';"); | |||||||||||||||||||||||||||
| 73 | 4 | $self->bump_exports; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | sub export_lib_to_env { &ENTER_TRACE_2; | ||||||||||||||||||||||||||
|
Subroutine
export_lib_to_env: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 4 | $self->expected_name("lib"); | |||||||||||||||||||||||||||
| 79 | 4 | ▶ | return unless my @libdirs = $self->found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($self->have_exported) { debug "already exported lib to env" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 4 | debug qq{use lib (@libdirs);}; | |||||||||||||||||||||||||||
| 82 | 4 | ▶ | eval q{use lib (@libdirs); 1} || die; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 4 | $self->bump_exports; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 4 | ▶ | sub export_bin_to_env { &ENTER_TRACE_2; | ||||||||||||||||||||||||||
|
Subroutine
export_bin_to_env: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 88 | 4 | $self->expected_name("bin"); | |||||||||||||||||||||||||||
| 89 | 4 | ▶ | return unless my @bindirs = $self->found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 2 | my @old_path = @PATH; | |||||||||||||||||||||||||||
| 91 | 2 | my @new_path = uniq @bindirs, @PATH; | |||||||||||||||||||||||||||
| 92 | 2 | ▶ | return if @old_path == @new_path && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@old_path == @new_path and join($", @old_path) eq join($", @new_path)
MC/DC0%0/2
@old_path == @new_path and join($", @old_path) eq join($", @new_path)
@old_path == @new_path
join($", @old_path) eq join($", @new_path)
Truth table33%1/3
A and B
A= @old_path == @new_pathB= join($", @old_path) eq join($", @new_path)
| |||||||||||||||||||||||||||||
| 93 | "@old_path" eq "@new_path"; | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($self->have_exported) { debug "already exported bin to env" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 2 | debug("\@PATH = (@new_path);"); | |||||||||||||||||||||||||||
| 96 | 2 | @PATH = @new_path; | |||||||||||||||||||||||||||
| 97 | 2 | $self->bump_exports; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 4 | ▶ | sub export_man_to_env { &ENTER_TRACE_2; | ||||||||||||||||||||||||||
|
Subroutine
export_man_to_env: called CC=9 SCAR=32.3
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 102 | 4 | $self->expected_name("man"); | |||||||||||||||||||||||||||
| 103 | 4 | ▶ | return unless my @mandirs = $self->found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($self->have_exported) { debug "already exported man to env" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 4 | ▶ | unless ($MANPATH) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 4 | local $/ = "\n"; | |||||||||||||||||||||||||||
| 107 | # temp variable so we don't clobber real one on error | ||||||||||||||||||||||||||||
| 108 | 4 | my $manpath = `manpath 2>&1`; | |||||||||||||||||||||||||||
| 109 | 2 | ▶ | chomp $manpath if defined $manpath; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 2 | ▶ | if ($?) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | debug("`manpath` command failed with wstat=$?: $manpath"); | |||||||||||||||||||||||||||
| 112 | 0 | $manpath = join ":", bin2man(); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 2 | ▶ | return unless $manpath; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | $MANPATH = $manpath; | |||||||||||||||||||||||||||
| 116 | 0 | debug("\$MANPATH = $MANPATH;"); | |||||||||||||||||||||||||||
| 117 | 0 | $self->bump_exports; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 0 | my @old_path = split /:/, $MANPATH, -1; | |||||||||||||||||||||||||||
| 120 | 0 | my @new_path = uniq @mandirs, @old_path; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | return if @old_path == @new_path && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@old_path == @new_path and join($", @old_path) eq join($", @new_path)
MC/DC0%0/2
@old_path == @new_path and join($", @old_path) eq join($", @new_path)
@old_path == @new_path
join($", @old_path) eq join($", @new_path)
Truth table0%0/3
A and B
A= @old_path == @new_pathB= join($", @old_path) eq join($", @new_path)
| |||||||||||||||||||||||||||||
| 122 | "@old_path" eq "@new_path"; | ||||||||||||||||||||||||||||
| 123 | 0 | $MANPATH = join ":", @new_path; | |||||||||||||||||||||||||||
| 124 | 0 | debug("\$MANPATH = $MANPATH;"); | |||||||||||||||||||||||||||
| 125 | 0 | debug("\@MANPATH = (@new_path);"); | |||||||||||||||||||||||||||
| 126 | 0 | $self->bump_exports; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 6 | 1; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||