| 1 | package Dynamic::Loader; | ||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 4 | require Exporter; | |||||||||||||||||||
| 5 | 4 | ▶ | use Carp qw/confess/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 4 | ▶ | use Env::Path; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 4 | ▶ | use File::Basename; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 4 | ▶ | require Data::Dumper if defined( $ENV{DEBUG} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | our ( $VERSION, $BINPATH, @ISA, @EXPORT ); | |||||||||||||||||||
| 11 | 4 | $VERSION = '1.08'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Dynamic::Loader - call a script without to know where is his location. | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | The Dynamic::Loader manage the dynamic location of scripts and bundles. | ||||||||||||||||||||
| 21 | Scripts and bundles are packaged in there own directory. | ||||||||||||||||||||
| 22 | The bundles and scripts locations are discribed on a named configuration file. | ||||||||||||||||||||
| 23 | The prefix configuration directory can be specified by the $JAVAPERL environnement. | ||||||||||||||||||||
| 24 | The default directory is $HOME/.perljava/conf, but you can specify a custom | ||||||||||||||||||||
| 25 | prefix with the $JAVAPERL/conf variable. | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | A configuration is <name>.conf with this format: | ||||||||||||||||||||
| 28 | prefix=<absolute path> | ||||||||||||||||||||
| 29 | bin=<relative binary dir> | ||||||||||||||||||||
| 30 | lib=<relative library dir> | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =head1 DEFAULT SCRIPT AND PARAMS | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | When C<Dynamic::Loader> is used, you can specify the script name and his options | ||||||||||||||||||||
| 36 | command: | ||||||||||||||||||||
| 37 | perl -S fromjar.pl scriptname.pl --a=... --b=... | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 4 | @ISA = qw(Exporter); | |||||||||||||||||||
| 43 | 4 | @EXPORT = qw($SCRIPTPATH $PATH $PERL5LIB &listScripts &getExecPrefix); | |||||||||||||||||||
| 44 | 4 | our ( $SCRIPTPATH, $PATH, $PERL5LIB, ); | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 4 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 47 | 4 | my $class = shift; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | #@_ contains what could be passed on -MLoader=...; iv ever | ||||||||||||||||||||
| 50 | 4 | init(); | |||||||||||||||||||
| 51 | 4 | $class->export_to_level( 1, $class, @_ ); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head3 init() | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | setup libs and bin directories | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | #fix lib and script path according to what's given | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 4 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||
| 63 | 4 | my $perlJavaHome; | |||||||||||||||||||
| 64 | 4 | ▶ | $perlJavaHome = $ENV{PERLLOADERHOME} || $ENV{JAVAPERL}; | ||||||||||||||||||
|
Condition66%2/3
$ENV{'PERLLOADERHOME'} || $ENV{'JAVAPERL'}
MC/DC50%1/2
$ENV{'PERLLOADERHOME'} || $ENV{'JAVAPERL'}
$ENV{'PERLLOADERHOME'}
$ENV{'JAVAPERL'}
Truth table66%2/3
A || B
A= $ENV{'PERLLOADERHOME'}B= $ENV{'JAVAPERL'}
| |||||||||||||||||||||
| 65 | 4 | ▶ | $perlJavaHome = "$ENV{HOME}/.perljava" unless defined $perlJavaHome; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | #$ENV{PATH}=''; | ||||||||||||||||||||
| 68 | 4 | $PATH = Env::Path->PATH; | |||||||||||||||||||
| 69 | 4 | $SCRIPTPATH = Env::Path->SCRIPTPATH; | |||||||||||||||||||
| 70 | 4 | $PERL5LIB = Env::Path->PERL5LIB; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | #TODO change that from ENV | ||||||||||||||||||||
| 73 | 4 | my @modules; | |||||||||||||||||||
| 74 | my %conffiles; | ||||||||||||||||||||
| 75 | 4 | ▶ | if ( $ENV{PERLLOADERMODULES} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 0 | @modules = split /:/, $ENV{PERLLOADERMODULES}; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||
| 79 | 4 | foreach (<$perlJavaHome/conf/*.conf>) { | |||||||||||||||||||
| 80 | 3 | ▶ | open( CONFIGFILE, $_ ) or next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 3 | my %entry = (); | |||||||||||||||||||
| 82 | 3 | ▶ | while ( my $l = <CONFIGFILE> ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 14 | ▶ | if ( $l =~ /^([^=]+)=(.*)/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 12 | my ( $key, $val ) = ( $1, $2 ); | |||||||||||||||||||
| 85 | 12 | ▶ | if ( $key eq "prefix" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 3 | $conffiles{$val} = \%entry; | |||||||||||||||||||
| 87 | 3 | push @modules, $val; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||
| 90 | 9 | $entry{$key} = $val; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | 3 | close CONFIGFILE; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | 4 | ▶ | require Data::Dumper if defined( $ENV{DEBUG} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | 4 | ▶ | printf Data::Dumper::Dumper( \%conffiles ) . "\n" if defined( $ENV{DEBUG} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 4 | foreach my $pjar (@modules) { | |||||||||||||||||||
| 101 | 3 | ▶ | eval "use lib \"$pjar/$conffiles{$pjar}->{lib}\""; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | #we wish to put the path from the given directory, but in the correct order, and in front of all other. | ||||||||||||||||||||
| 105 | 4 | foreach my $pjar ( reverse @modules ) { | |||||||||||||||||||
| 106 | 3 | my $bin = "$pjar/$conffiles{$pjar}->{bin}"; | |||||||||||||||||||
| 107 | 3 | $bin =~ s/\/\//\//g; | |||||||||||||||||||
| 108 | 3 | ▶ | $SCRIPTPATH->Prepend($bin) unless $SCRIPTPATH->Contains($bin); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | 3 | ▶ | $PATH->Prepend($bin) unless $PATH->Contains($bin); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 3 | my $lib = "$pjar/$conffiles{$pjar}->{lib}"; | |||||||||||||||||||
| 111 | 3 | $lib =~ s/\/\//\//g; | |||||||||||||||||||
| 112 | 3 | ▶ | $PERL5LIB->Prepend($lib) unless $PERL5LIB->Contains($lib); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =head3 Dynamic::Loader::listScripts([patt]) | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | Return a list of commands following a pattern listScripts(), listScripts("*.pl"), listScripts("phe*") | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | The commands returned here are returned with a relative path to the package they belong to | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 1 | ▶ | sub listScripts { | ||||||||||||||||||
|
Subroutine
listScripts: called CC=5 SCAR=32.1
Pod
documented
| |||||||||||||||||||||
| 126 | 1 | require File::Find::Rule; | |||||||||||||||||||
| 127 | 0 | ▶ | my $patt = shift || '*'; | ||||||||||||||||||
|
Condition0%0/2
shift() || '*'
MC/DC0%0/1
shift() || '*'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 0 | my @tmp; | |||||||||||||||||||
| 130 | 0 | foreach my $p ( $SCRIPTPATH->List ) { | |||||||||||||||||||
| 131 | 0 | foreach ( File::Find::Rule->file()->name($patt)->in($p) ) { | |||||||||||||||||||
| 132 | 0 | ▶ | next if /\/\.svn\//; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | 0 | s/^$p([\/\\])?//; | |||||||||||||||||||
| 134 | 0 | push @tmp, $_; | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | 0 | return @tmp; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =head3 Dynamic::Loader::getScript(relative_path) | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | Return the complete path to the given scripts. | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | Contrary to listScripts(), this command must return exactly one script and will die if not; | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 3 | ▶ | sub getScript { | ||||||||||||||||||
|
Subroutine
getScript: called CC=11 SCAR=27.9
Pod
documented
| |||||||||||||||||||||
| 149 | 3 | ▶ | my $relPath = shift or confess "no relative path given"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | 3 | my @tmp; | |||||||||||||||||||
| 151 | 3 | foreach ( $SCRIPTPATH->List ) { | |||||||||||||||||||
| 152 | 3 | my $full = "$_/$relPath"; | |||||||||||||||||||
| 153 | 3 | ▶ | push @tmp, $full if -f $full; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | 3 | ▶ | confess "no script found for [$relPath]" unless @tmp; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | 3 | my $contents; | |||||||||||||||||||
| 157 | 3 | ▶ | if (@tmp) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 3 | local $/; | |||||||||||||||||||
| 159 | 3 | foreach my $f (@tmp) { | |||||||||||||||||||
| 160 | 3 | ▶ | open( FD, "<$f" ) or die "cannot read $f"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 161 | 3 | my $tmp = <FD>; | |||||||||||||||||||
| 162 | 3 | close FD; | |||||||||||||||||||
| 163 | 3 | ▶ | unless ($contents) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 164 | 3 | $contents = $tmp; | |||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | else { | ||||||||||||||||||||
| 167 | 0 | ▶ | if ( $contents ne $tmp ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 168 | 0 | ▶ | confess | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 169 | "multiple scripts found with incompatible contents for [$relPath] in " | ||||||||||||||||||||
| 170 | . join(@tmp) | ||||||||||||||||||||
| 171 | if @tmp > 1; | ||||||||||||||||||||
| 172 | } | ||||||||||||||||||||
| 173 | } | ||||||||||||||||||||
| 174 | } | ||||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | 3 | return $tmp[0]; | |||||||||||||||||||
| 177 | } | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | =head3 Dynamic::Loader::getLibs(relative_path) | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | Return the complete path to the given scripts + the complete perl prefix with perl5libs. | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | =cut | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 1 | ▶ | sub getLongScript { | ||||||||||||||||||
|
Subroutine
getLongScript: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||
| 186 | 1 | ▶ | my $relPath = shift or confess "no relative path given"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 187 | 1 | my $path = getScript($relPath); | |||||||||||||||||||
| 188 | 1 | my $p5l = "$^X "; | |||||||||||||||||||
| 189 | 1 | foreach ( $PERL5LIB->List ) { | |||||||||||||||||||
| 190 | 3 | $p5l .= "-I$_ "; | |||||||||||||||||||
| 191 | } | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 1 | ▶ | printf "---> $p5l$path \n" if defined( $ENV{DEBUG} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 194 | 1 | return "$p5l$path"; | |||||||||||||||||||
| 195 | } | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | =head3 Dynamic::Loader::getExecPrefix() | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | return an array to prepend to execution (perl, includes etc...) | ||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | 1 | ▶ | sub getExecPrefix { | ||||||||||||||||||
|
Subroutine
getExecPrefix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 204 | 1 | return ($^X); | |||||||||||||||||||
| 205 | } | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | =head3 Dynamic::Loader::whence([pat]) | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | return a list of commands with the full path corresponding to a pattern. Think of ls completion in bash | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | =cut | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | 0 | ▶ | sub whence { | ||||||||||||||||||
|
Subroutine
whence: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 214 | 0 | ▶ | return $SCRIPTPATH->Whence( $_[0] or "*" ); | ||||||||||||||||||
|
Condition0%0/2
$_[0] || '*'
MC/DC0%0/1
$_[0] || '*'
$_[0]
Truth table0%0/2
A
A= $_[0]
| |||||||||||||||||||||
| 215 | } | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | =head1 AUTHOR | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | Olivier Evalet, C<< <olivier.evalet at genebio.com> >> | ||||||||||||||||||||
| 220 | Alexandre Masselo C<< <alex at genebio.com> >> | ||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | =head1 BUGS | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | Please report any bugs or feature requests to C<bug-dynamic-loader at rt.cpan.org>, or through | ||||||||||||||||||||
| 225 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dynamic-Loader>. I will be notified, and then you'll | ||||||||||||||||||||
| 226 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | =head1 SUPPORT | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | perldoc Dynamic::Loader | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | You can also look for information at: | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | =over 4 | ||||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | =item * RT: CPAN's request tracker | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dynamic-Loader> | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | L<http://annocpan.org/dist/Dynamic-Loader> | ||||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | =item * CPAN Ratings | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | L<http://cpanratings.perl.org/d/Dynamic-Loader> | ||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | =item * Search CPAN | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | L<http://search.cpan.org/dist/Dynamic-Loader> | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | =back | ||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||
| 262 | |||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | Copyright 2008 Olivier Evalet, Alexandre Masselot all rights reserved. | ||||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 269 | under the same terms as Perl itself. | ||||||||||||||||||||
| 270 | |||||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | =cut | ||||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | 4 | 1; # End of Dynamic::Loader | |||||||||||||||||||