| 1 | package FindApp::Object::Behavior::Loader; | ||||||||||
| 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 | |||||||||||
| 10 | 6 | my %Internal = map { $_ => 1 } @CARP_NOT; | |||||||||
| 11 | |||||||||||
| 12 | 4 | ▶ | sub foreign_caller { | ||||||||
|
Subroutine
foreign_caller: called CC=7 SCAR=20.1
| |||||||||||
| 13 | 4 | my $frame = 0; | |||||||||
| 14 | 4 | my($pkg, $file, $line, $sub); | |||||||||
| 15 | 4 | while (1) { | |||||||||
| 16 | 40 | ($pkg, $file, $line, $sub) = caller($frame); | |||||||||
| 17 | 40 | ▶ | last unless $pkg; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 40 | ▶ | last if $sub eq "FindApp::Exporter::import"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 40 | ▶ | last unless $pkg =~ /^FindApp\b/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 36 | ▶ | last unless $Internal{$pkg}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 36 | $frame++; | |||||||||
| 22 | 36 | ▶ | panic("runaway frame search") if $frame > 100; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | } | ||||||||||
| 24 | 4 | ▶ | croak "can't find importing package" unless $pkg; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 4 | return $pkg; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 6 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | |||||||||||
| 30 | 6 | ▶ | use pluskeys qw{ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | MODULES_USED | ||||||||||
| 32 | FILES_REQUIRED | ||||||||||
| 33 | 6 | }; | |||||||||
| 34 | |||||||||||
| 35 | 14 | ▶ | sub init { &ENTER_TRACE; | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | 14 | my($self) = @_; | |||||||||
| 37 | 14 | $self->maybe::next::method; | |||||||||
| 38 | 14 | $$self{+MODULES_USED} = []; | |||||||||
| 39 | 14 | $$self{+FILES_REQUIRED} = []; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | # overrides the f:o:Behavior method, not the f:o:s:Group Method. | ||||||||||
| 43 | 4 | ▶ | sub export_lib_to_env { &ENTER_TRACE; | ||||||||
|
Subroutine
export_lib_to_env: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 44 | 4 | my $self = &myself; | |||||||||
| 45 | 4 | $self->next::method(@_); # first get @INC setup | |||||||||
| 46 | 4 | $self->load_wanted; # so we can load whatever they asked for | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 4 | ▶ | sub load_wanted { &ENTER_TRACE; | ||||||||
|
Subroutine
load_wanted: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 50 | 4 | my $self = &myself; | |||||||||
| 51 | 4 | ▶ | return unless my @wanted = map { $self->$_->wanted } <rootdir libdirs>; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 4 | $self->load_libraries(@wanted); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 4 | ▶ | sub load_libraries { &ENTER_TRACE; | ||||||||
|
Subroutine
load_libraries: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 56 | 4 | my $self = &myself; | |||||||||
| 57 | 4 | ▶ | return unless @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 4 | $self->load_modules(grep /^\w+(?:::\w+)+$/ => @_); | |||||||||
| 59 | 4 | $self->load_files (grep /\.p[lm]$/ => @_); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 4 | ▶ | sub load_modules { &ENTER_TRACE; | ||||||||
|
Subroutine
load_modules: called CC=3 SCAR=16.5
Pod
documented
| |||||||||||
| 63 | 4 | my($self, $caller) = (&myself, &foreign_caller); | |||||||||
| 64 | 4 | for my $mod (@_) { | |||||||||
| 65 | 0 | debug "load $mod into $caller"; | |||||||||
| 66 | 0 | ▶ | eval qq{package $caller; use $mod; 1} || die; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $self->another_module_used($mod); | |||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | sub another_module_used { | ||||||||
|
Subroutine
another_module_used: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 72 | 0 | ▶ | my $self = &myself; | ||||||||
|
Subroutine
another_module_used: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 73 | 0 | push @{ $$self{+MODULES_USED} }, @_; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub used_modules { | ||||||||
|
Subroutine
used_modules: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 77 | 0 | ▶ | my $self = &myself; | ||||||||
|
Pod
documented
| |||||||||||
| 78 | 0 | @{ $$self{+MODULES_USED} }; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 4 | ▶ | sub load_files { &ENTER_TRACE; | ||||||||
|
Subroutine
load_files: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||
| 82 | 4 | my $self = &myself; | |||||||||
| 83 | 4 | for my $file (@_) { | |||||||||
| 84 | 0 | require "$file"; # the "new" version stuff has messed this all up! | |||||||||
| 85 | 0 | $self->another_file_required($file); | |||||||||
| 86 | } | ||||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | sub another_file_required { | ||||||||
|
Subroutine
another_file_required: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 90 | 0 | my $self = &myself; | |||||||||
| 91 | 0 | push @{ $$self{+FILES_REQUIRED} }, @_; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | sub required_files { | ||||||||
|
Subroutine
required_files: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 95 | 0 | my $self = &myself; | |||||||||
| 96 | 0 | @{ $$self{+FILES_REQUIRED} }; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 6 | 1; | |||||||||
| 100 | |||||||||||
| 101 | =encoding utf8 | ||||||||||
| 102 | |||||||||||
| 103 | =head1 NAME | ||||||||||
| 104 | |||||||||||
| 105 | FindApp::Loader - FIXME | ||||||||||
| 106 | |||||||||||
| 107 | =head1 SYNOPSIS | ||||||||||
| 108 | |||||||||||
| 109 | use FindApp::Loader; | ||||||||||
| 110 | |||||||||||
| 111 | =head1 DESCRIPTION | ||||||||||
| 112 | |||||||||||
| 113 | =head2 Pluskey Attributes | ||||||||||
| 114 | |||||||||||
| 115 | These are all private; use the methods instead. | ||||||||||
| 116 | |||||||||||
| 117 | =over | ||||||||||
| 118 | |||||||||||
| 119 | =item MODULES_USED | ||||||||||
| 120 | |||||||||||
| 121 | Reference to array of modules actually used. | ||||||||||
| 122 | |||||||||||
| 123 | =item FILES_REQUIRED | ||||||||||
| 124 | |||||||||||
| 125 | Reference to array of files actually required. | ||||||||||
| 126 | |||||||||||
| 127 | =back | ||||||||||
| 128 | |||||||||||
| 129 | =head2 Methods | ||||||||||
| 130 | |||||||||||
| 131 | =over | ||||||||||
| 132 | |||||||||||
| 133 | =item another_file_required | ||||||||||
| 134 | |||||||||||
| 135 | =item another_module_used | ||||||||||
| 136 | |||||||||||
| 137 | =item export_lib_to_env | ||||||||||
| 138 | |||||||||||
| 139 | =item load_files | ||||||||||
| 140 | |||||||||||
| 141 | =item load_libraries | ||||||||||
| 142 | |||||||||||
| 143 | =item load_modules | ||||||||||
| 144 | |||||||||||
| 145 | =item load_wanted | ||||||||||
| 146 | |||||||||||
| 147 | =item required_files | ||||||||||
| 148 | |||||||||||
| 149 | =item used_modules | ||||||||||
| 150 | |||||||||||
| 151 | =back | ||||||||||
| 152 | |||||||||||
| 153 | =head1 EXAMPLES | ||||||||||
| 154 | |||||||||||
| 155 | =head1 ENVIRONMENT | ||||||||||
| 156 | |||||||||||
| 157 | =head1 SEE ALSO | ||||||||||
| 158 | |||||||||||
| 159 | =over | ||||||||||
| 160 | |||||||||||
| 161 | =item L<FindApp> | ||||||||||
| 162 | |||||||||||
| 163 | =back | ||||||||||
| 164 | |||||||||||
| 165 | =head1 CAVEATS AND PROVISOS | ||||||||||
| 166 | |||||||||||
| 167 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 168 | |||||||||||
| 169 | =head1 HISTORY | ||||||||||
| 170 | |||||||||||
| 171 | =head1 AUTHOR | ||||||||||
| 172 | |||||||||||
| 173 | Tom Christiansen C<< <tchrist@perl.com> >> | ||||||||||
| 174 | |||||||||||
| 175 | =head1 LICENCE AND COPYRIGHT | ||||||||||
| 176 | |||||||||||
| 177 | Copyright (c) 2016, Tom Christiansen C<< <tchrist@perl.com> >>. | ||||||||||
| 178 | All Rights Reserved. | ||||||||||
| 179 | |||||||||||
| 180 | This module is free software; you can redistribute it and/or | ||||||||||
| 181 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||
| 182 | |||||||||||
| 183 | =cut | ||||||||||
| 184 | |||||||||||