File Coverage

blib/lib/Module/Info.pm
Criterion Covered Total %
statement 250 264 94.7
branch 59 76 77.6
condition 19 37 51.3
subroutine 47 48 97.9
pod 20 20 100.0
total 395 445 88.7


line stmt bran cond sub pod time code
1             package Module::Info;
2              
3 6     6   51908 use 5.006;
  6         20  
4 6     5   88 use strict;
  5         10  
  5         119  
5 5     5   34 use warnings;
  5         9  
  5         160  
6 5     5   24 use Carp;
  5         8  
  5         407  
7 5     5   29 use File::Spec;
  5         9  
  5         127  
8 5     5   23 use Config;
  5         8  
  5         19002  
9              
10 5     5   3094 my $has_version_pm = eval 'use version; 1';
  5         8513  
  5         32  
11              
12             our $AUTOLOAD;
13             our $VERSION;
14              
15 5     5   31 $VERSION = eval 'use version; 1' ? 'version'->new('0.35_07') : '0.35_07';
  5         43  
  5         23  
16             $VERSION = eval $VERSION;
17              
18              
19             =head1 NAME
20              
21             Module::Info - Information about Perl modules
22              
23             =head1 SYNOPSIS
24              
25             use Module::Info;
26              
27             my $mod = Module::Info->new_from_file('Some/Module.pm');
28             my $mod = Module::Info->new_from_module('Some::Module');
29             my $mod = Module::Info->new_from_loaded('Some::Module');
30              
31             my @mods = Module::Info->all_installed('Some::Module');
32              
33             my $name = $mod->name;
34             my $version = $mod->version;
35             my $dir = $mod->inc_dir;
36             my $file = $mod->file;
37             my $is_core = $mod->is_core;
38              
39             # Only available in perl 5.6.1 and up.
40             # These do compile the module.
41             my @packages = $mod->packages_inside;
42             my @used = $mod->modules_used;
43             my @subs = $mod->subroutines;
44             my @isa = $mod->superclasses;
45             my @calls = $mod->subroutines_called;
46              
47             # Check for constructs which make perl hard to predict.
48             my @methods = $mod->dynamic_method_calls;
49             my @lines = $mod->eval_string; *UNIMPLEMENTED*
50             my @lines = $mod->gotos; *UNIMPLEMENTED*
51             my @controls = $mod->exit_via_loop_control; *UNIMPLEMENTED*
52             my @unpredictables = $mod->has_unpredictables; *UNIMPLEMENTED*
53              
54             # set/get Module::Info options
55             $self->die_on_compilation_error(1);
56             my $die_on_error = $mod->die_on_compilation_error;
57             $self->safe(1);
58             my $safe = $mod->safe;
59              
60             =head1 DESCRIPTION
61              
62             Module::Info gives you information about Perl modules B
63             actually loading the module>. It actually isn't specific to modules
64             and should work on any perl code.
65              
66             =head1 METHODS
67              
68             =head2 Constructors
69              
70             There are a few ways to specify which module you want information for.
71             They all return Module::Info objects.
72              
73             =over 4
74              
75             =item new_from_file
76              
77             my $module = Module::Info->new_from_file('path/to/Some/Module.pm');
78              
79             Given a file, it will interpret this as the module you want
80             information about. You can also hand it a perl script.
81              
82             If the file doesn't exist or isn't readable it will return false.
83              
84             =cut
85              
86             sub new_from_file {
87 22     22 1 1250 my($proto, $file) = @_;
88 22   33     130 my($class) = ref $proto || $proto;
89              
90 22 100       467 return unless -r $file;
91              
92 21         47 my $self = {};
93 21         514 $self->{file} = File::Spec->rel2abs($file);
94 21         60 $self->{dir} = '';
95 21         45 $self->{name} = '';
96 21         47 $self->{safe} = 0;
97 21         39 $self->{use_version} = 0;
98              
99 21         78 return bless $self, $class;
100             }
101              
102             =item new_from_module
103              
104             my $module = Module::Info->new_from_module('Some::Module');
105             my $module = Module::Info->new_from_module('Some::Module', @INC);
106              
107             Given a module name, @INC will be searched and the first module found
108             used. This is the same module that would be loaded if you just say
109             C.
110              
111             If you give your own @INC, that will be used to search instead.
112              
113             =cut
114              
115             sub new_from_module {
116 13     13 1 2396 my($class, $module, @inc) = @_;
117 13         96 return ($class->_find_all_installed($module, 1, @inc))[0];
118             }
119              
120             =item new_from_loaded
121              
122             my $module = Module::Info->new_from_loaded('Some::Module');
123              
124             Gets information about the currently loaded version of Some::Module.
125             If it isn't loaded, returns false.
126              
127             =cut
128              
129             sub new_from_loaded {
130 2     2 1 860 my($class, $name) = @_;
131              
132 2         11 my $mod_file = join('/', split('::', $name)) . '.pm';
133 2   100     20 my $filepath = $INC{$mod_file} || '';
134              
135 2 100       6 my $module = Module::Info->new_from_file($filepath) or return;
136 1         2 $module->{name} = $name;
137 1         32 ($module->{dir} = $filepath) =~ s|/?\Q$mod_file\E$||;
138 1         11 $module->{dir} = File::Spec->rel2abs($module->{dir});
139 1         2 $module->{safe} = 0;
140 1         4 $module->{use_version} = 0;
141              
142 1         4 return $module;
143             }
144              
145             =item all_installed
146              
147             my @modules = Module::Info->all_installed('Some::Module');
148             my @modules = Module::Info->all_installed('Some::Module', @INC);
149              
150             Like new_from_module(), except I modules in @INC will be
151             returned, in the order they are found. Thus $modules[0] is the one
152             that would be loaded by C.
153              
154             =cut
155              
156             sub all_installed {
157 2     2 1 8 my($class, $module, @inc) = @_;
158 2         8 return $class->_find_all_installed($module, 0, @inc);
159             }
160              
161             # Thieved from Module::InstalledVersion
162             sub _find_all_installed {
163 15     15   42 my($proto, $name, $find_first_one, @inc) = @_;
164 15   33     91 my($class) = ref $proto || $proto;
165              
166 15 100       131 @inc = @INC unless @inc;
167 15         258 my $file = File::Spec->catfile(split /::/, $name) . '.pm';
168              
169 15         39 my @modules = ();
170 15         34 DIR: foreach my $dir (@inc) {
171             # Skip the new code ref in @INC feature.
172 37 100       103 next if ref $dir;
173              
174 36         379 my $filename = File::Spec->catfile($dir, $file);
175 36 100       1031 if( -r $filename ) {
176 17         61 my $module = $class->new_from_file($filename);
177 17         225 $module->{dir} = File::Spec->rel2abs($dir);
178 17         40 $module->{name} = $name;
179 17         100 push @modules, $module;
180 17 100       69 last DIR if $find_first_one;
181             }
182             }
183              
184 15         88 return @modules;
185             }
186              
187              
188             =back
189              
190             =head2 Information without loading
191              
192             The following methods get their information without actually compiling
193             the module.
194              
195             =over 4
196              
197             =item B
198              
199             my $name = $module->name;
200             $module->name($name);
201              
202             Name of the module (ie. Some::Module).
203              
204             Module loaded using new_from_file() won't have this information in
205             which case you can set it yourself.
206              
207             =cut
208              
209             sub name {
210 9     9 1 3628 my($self) = shift;
211              
212 9 100       46 $self->{name} = shift if @_;
213 9         50 return $self->{name};
214             }
215              
216             =item B
217              
218             my $version = $module->version;
219              
220             Divines the value of $VERSION. This uses the same method as
221             ExtUtils::MakeMaker and all caveats therein apply.
222              
223             =cut
224              
225             # Thieved from ExtUtils::MM_Unix 1.12603
226             sub version {
227 14     14 1 37 my($self) = shift;
228 14         66 local($_, *MOD);
229              
230 14         43 my $parsefile = $self->file;
231 14         40 my $safe = $self->safe;
232              
233 14 50       862 open(MOD, $parsefile) or die $!;
234              
235 14         38 my $inpod = 0;
236 14         21 my $result;
237 14         261 while () {
238 108 50       322 $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
    50          
239 108 100 66     547 next if $inpod || /^\s*#/;
240              
241 103         144 chomp;
242             # taken from ExtUtils::MM_Unix 6.63_02
243 103 50       312 next if /^\s*(if|unless|elsif)/;
244 103 100       305 if (m{^\s*package\s+\w[\w\:\']*\s+(v?[0-9._]+)\s*;}) {
245 1         6 local $^W = 0;
246 1         3 $result = $1;
247 1         4 last;
248             }
249 102 100       605 next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
250 13 100       147 my $eval = sprintf qq{
251             package Module::Info::_version;
252             %s
253              
254             local $1$2;
255             \$$2=undef; do {
256             %s
257             }; \$$2
258             }, ( $safe ? '' : 'no strict;' ), $_;
259 13         63 local $^W = 0;
260 13         96 $result = $self->_eval($eval);
261 13 50 33     1494 warn "Could not eval '$eval' in $parsefile: $@" if $@ && !$safe;
262 13 100       38 $result = "undef" unless defined $result;
263 13         35 last;
264             }
265 14         220 close MOD;
266 14 100 33     46 $result = 'version'->new($result) # quotes for 5.004
      66        
267             if $self->use_version
268             && (!ref($result) || !UNIVERSAL::isa($result, "version"));
269 14         108 return $result;
270             }
271              
272              
273             =item B
274              
275             my $dir = $module->inc_dir;
276              
277             Include directory in which this module was found. Module::Info
278             objects created with new_from_file() won't have this info.
279              
280             =cut
281              
282             sub inc_dir {
283 8     8 1 23 my($self) = shift;
284              
285 8         158 return $self->{dir};
286             }
287              
288             =item B
289              
290             my $file = $module->file;
291              
292             The absolute path to this module.
293              
294             =cut
295              
296             sub file {
297 44     44 1 112 my($self) = shift;
298              
299 44         258 return $self->{file};
300             }
301              
302             =item B
303              
304             my $is_core = $module->is_core;
305              
306             Checks if this module is the one distributed with Perl.
307              
308             B This goes by what directory it's in. It's possible that the
309             module has been altered or upgraded from CPAN since the original Perl
310             installation.
311              
312             =cut
313              
314             sub is_core {
315 5     5 1 15 my($self) = shift;
316              
317             return scalar grep $self->{dir} eq File::Spec->canonpath($_),
318             ($Config{installarchlib},
319             $Config{installprivlib},
320             $Config{archlib},
321 5         398 $Config{privlib});
322             }
323              
324             =back
325              
326             =head2 Information that requires loading.
327              
328             B From here down reliability drops rapidly!
329              
330             The following methods get their information by compiling the module
331             and examining the opcode tree. The module will be compiled in a
332             separate process so as not to disturb the current program.
333              
334             They will only work on 5.6.1 and up and requires the B::Utils module.
335              
336             =over 4
337              
338             =item B
339              
340             my @packages = $module->packages_inside;
341              
342             Looks for any explicit C declarations inside the module and
343             returns a list. Useful for finding hidden classes and functionality
344             (like Tie::StdHandle inside Tie::Handle).
345              
346             B Currently doesn't spot package changes inside subroutines.
347              
348             =cut
349              
350             sub packages_inside {
351 7     7 1 650 my $self = shift;
352              
353 7         33 my %packs = map {$_, 1} $self->_call_B('packages');
  15         133  
354 6         106 return keys %packs;
355             }
356              
357             =item B
358              
359             my %versions = $module->package_versions;
360              
361             Returns a hash whose keys are the packages contained in the module
362             (these are the same as what's returned by C), and
363             whose values are the versions of those packages.
364              
365             =cut
366              
367             sub package_versions {
368 2     2 1 2039 my $self = shift;
369              
370 2         14 my @packs = $self->packages_inside;
371              
372             # To survive the print(), we translate undef into '~' and then back again.
373 2         45 (my $quoted_file = $self->file) =~ s/(['\\])/\\$1/g;
374 2         17 my $command = qq{-le "require '$quoted_file';};
375 2         15 foreach (@packs) {
376 5         32 $command .= " print defined $_->VERSION ? $_->VERSION : '~';"
377             }
378 2         6 $command .= qq{"};
379              
380 2         51 my ($status, @versions) = $self->_call_perl($command);
381 2         37 chomp @versions;
382 2         22 foreach (@versions) {
383 5 100       46 $_ = undef if $_ eq '~';
384             }
385              
386 2         6 my %map;
387 2         41 @map{@packs} = @versions;
388              
389 2         107 return %map;
390             }
391              
392              
393             =item B
394              
395             my @used = $module->modules_used;
396              
397             Returns a list of all modules and files which may be C'd or
398             C'd by this module.
399              
400             B These modules may be conditionally loaded, can't tell. Also
401             can't find modules which might be used inside an C.
402              
403             =cut
404              
405             sub modules_used {
406 3     3 1 3303 my($self) = shift;
407 3         16 my %used = $self->modules_required;
408              
409 3         106 return keys %used;
410             }
411              
412             =item B
413              
414             my %required = $module->modules_required;
415              
416             Returns a list of all modules and files which may be C'd or
417             C'd by this module, together with the minimum required version.
418              
419             The hash is keyed on the module/file name, the corrisponding value is
420             an array reference containing the requied versions, or an empty array
421             if no specific version was required.
422              
423             B These modules may be conditionally loaded, can't tell. Also
424             can't find modules which might be used inside an C.
425              
426             =cut
427              
428             sub modules_required {
429 4     4 1 26 my($self) = shift;
430              
431 4         27 my $mod_file = $self->file;
432 4         28 my @mods = $self->_call_B('modules_used');
433              
434 4         45 my @used_mods = ();
435 4         38 my %used_mods = ();
436 4   66     927 for (grep /^use \D/ && /at "\Q$mod_file\E" /, @mods) {
437 18         186 my($file, $version) = /^use (\S+) \(([^\)]*)\)/;
438 18   100     106 $used_mods{_file2mod($file)} ||= [];
439 18 100 66     214 next unless defined $version and length $version;
440              
441 6         48 push @{$used_mods{_file2mod($file)}}, $version;
  6         105  
442             }
443              
444 4         49 push @used_mods, map { my($file) = /^require bare (\S+)/; _file2mod($file) }
  8         51  
  8         39  
445             grep /^require bare \D/ , @mods;
446              
447 4         45 push @used_mods, map { /^require not bare (\S+)/; $1 }
  3         23  
  3         28  
448             grep /^require not bare \D/, @mods;
449              
450 4         21 foreach ( @used_mods ) { $used_mods{$_} = [] };
  11         102  
451 4         86 return %used_mods;
452             }
453              
454             sub _file2mod {
455 32     32   101 my($mod) = shift;
456 32         156 $mod =~ s/\.pm//;
457 32         88 $mod =~ s|/|::|g;
458 32         307 return $mod;
459             }
460              
461              
462             =item B
463              
464             my %subs = $module->subroutines;
465              
466             Returns a hash of all subroutines defined inside this module and some
467             info about it. The key is the *full* name of the subroutine
468             (ie. $subs{'Some::Module::foo'} rather than just $subs{'foo'}), value
469             is a hash ref with information about the subroutine like so:
470              
471             start => line number of the first statement in the subroutine
472             end => line number of the last statement in the subroutine
473              
474             Note that the line numbers may not be entirely accurate and will
475             change as perl's backend compiler improves. They typically correspond
476             to the first and last I statements in a subroutine. For
477             example:
478              
479             sub foo {
480             package Wibble;
481             $foo = "bar";
482             return $foo;
483             }
484              
485             Taking C as line 1, Module::Info will report line 3 as the
486             start and line 4 as the end. C is a compile-time
487             statement. Again, this will change as perl changes.
488              
489             Note this only catches simple C subroutine
490             declarations. Anonymous, autoloaded or eval'd subroutines are not
491             listed.
492              
493             =cut
494              
495             sub subroutines {
496 2     2 1 3072 my($self) = shift;
497              
498 2         25 my $mod_file = $self->file;
499 2         32 my @subs = $self->_call_B('subroutines');
500 2         4057 return map { /^(\S+) at "[^"]+" from (\d+) to (\d+)/;
  34         219  
501 34         711 ($1 => { start => $2, end => $3 }) }
502             grep /at "\Q$mod_file\E" /, @subs;
503             }
504              
505 16     16   56 sub _get_extra_arguments { '' }
506              
507             sub _call_B {
508 15     15   79 my($self, $arg) = @_;
509              
510 15         73 my $mod_file = $self->file;
511 15         77 my $extra_args = $self->_get_extra_arguments;
512 15         66 my $command = qq{$extra_args "-MO=Module::Info,$arg" "$mod_file"};
513 15         209 my($status, @out) = $self->_call_perl($command);
514              
515 15 100       383 if( $status ) {
516 2         25 my $exit = $status >> 8;
517 2         35 my $msg = join "\n",
518             "B::Module::Info,$arg use failed with $exit saying:",
519             @out;
520              
521 2 100       49 if( $self->{die_on_compilation_error} ) {
522 1         102 die $msg;
523             }
524             else {
525 1         74 warn $msg;
526 1         40 return;
527             }
528             }
529              
530 13         2048 @out = grep !/syntax OK$/, @out;
531 13         551 chomp @out;
532 13         1065 return @out;
533             }
534              
535              
536             =item B
537              
538             my @isa = $module->superclasses;
539              
540             Returns the value of @ISA for this $module. Requires that
541             $module->name be set to work.
542              
543             B superclasses() is currently cheating. See L below.
544              
545             =cut
546              
547             sub superclasses {
548 1     1 1 18 my $self = shift;
549              
550 1         14 my $mod_file = $self->file;
551 1         9 my $mod_name = $self->name;
552 1 50       10 unless( $mod_name ) {
553 0         0 carp 'isa() requires $module->name to be set';
554 0         0 return;
555             }
556              
557 1         13 my $extra_args = $self->_get_extra_arguments;
558 1         8 my $command =
559             qq{-e "require q{$mod_file}; print join qq{\\n}, \@$mod_name\::ISA"};
560 1         23 my($status, @isa) = $self->_call_perl("$extra_args $command");
561 1         29 chomp @isa;
562 1         41 return @isa;
563             }
564              
565             =item B
566              
567             my @calls = $module->subroutines_called;
568              
569             Finds all the methods and functions which are called inside the
570             $module.
571              
572             Returns a list of hashes. Each hash represents a single function or
573             method call and has the keys:
574              
575             line line number where this call originated
576             class class called on if its a class method
577             type function, symbolic function, object method,
578             class method, dynamic object method or
579             dynamic class method.
580             (NOTE This format will probably change)
581             name name of the function/method called if not dynamic
582              
583              
584             =cut
585              
586             sub subroutines_called {
587 2     2 1 1646 my($self) = shift;
588              
589 2         29 my @subs = $self->_call_B('subs_called');
590 2         86 my $mod_file = $self->file;
591              
592 2         2188 @subs = grep /at "\Q$mod_file\E" line/, @subs;
593 2         14 my @out = ();
594 2         19 foreach (@subs) {
595 26         60 my %info = ();
596 26         184 ($info{type}) = /^(.+) call/;
597 26 100       107 $info{type} = 'symbolic function' if /using symbolic ref/;
598 26         110 ($info{'name'}) = /to (\S+)/;
599 26         103 ($info{class})= /via (\S+)/;
600 26         132 ($info{line}) = /line (\d+)/;
601 26         90 push @out, \%info;
602             }
603 2         98 return @out;
604             }
605              
606             =back
607              
608             =head2 Information about Unpredictable Constructs
609              
610             Unpredictable constructs are things that make a Perl program hard to
611             predict what its going to do without actually running it. There's
612             nothing wrong with these constructs, but its nice to know where they
613             are when maintaining a piece of code.
614              
615             =over 4
616              
617             =item B
618              
619             my @methods = $module->dynamic_method_calls;
620              
621             Returns a list of dynamic method calls (ie. C<$obj->$method()>) used
622             by the $module. @methods has the same format as the return value of
623             subroutines_called().
624              
625             =cut
626              
627             sub dynamic_method_calls {
628 1     1 1 3008 my($self) = shift;
629 1         10 return grep $_->{type} =~ /dynamic/, $self->subroutines_called;
630             }
631              
632             =back
633              
634             =head2 Options
635              
636             The following methods get/set specific option values for the
637             Module::Info object.
638              
639             =over 4
640              
641             =item B
642              
643             $module->die_on_compilation_error(0); # default
644             $module->die_on_compilation_error(1);
645             my $flag = $module->die_on_compilation_error;
646              
647             Sets/gets the "die on compilation error" flag. When the flag is off
648             (default), and a module fails to compile, Module::Info simply emits a
649             watning and continues. When the flag is on and a module fails to
650             compile, Module::Info Cs with the same error message it would use
651             in the warning.
652              
653             =cut
654              
655             sub die_on_compilation_error {
656 2     2 1 787 my($self) = shift;
657              
658 2 50       25 $self->{die_on_compilation_error} = $_[0] ? 1 : 0 if @_;
    50          
659 2         8 return $self->{die_on_compilation_error};
660             }
661              
662             =item B
663              
664             $module->safe(0); # default
665             $module->safe(1); # be safer
666             my $flag = $module->safe;
667              
668             Sets/gets the "safe" flag. When the flag is enabled all operations
669             requiring module compilation are forbidden and the C method
670             executes its code in a C compartment.
671              
672             =cut
673              
674             sub safe {
675 50     50 1 118 my($self) = shift;
676              
677 50 100       174 if( @_ ) {
678 2 50       7 $self->{safe} = $_[0] ? 1 : 0;
679 2 50       25084 require Safe if $self->{safe};
680             }
681 50         56996 return $self->{safe};
682             }
683              
684             sub AUTOLOAD {
685 31 100   31   163 my($super) = $_[0]->safe ? 'Module::Info::Safe' : 'Module::Info::Unsafe';
686 31         118 my($method) = $AUTOLOAD;
687 31         300 $method =~ s/^.*::([^:]+)$/$1/;
688              
689 31 50       121 return if $method eq 'DESTROY';
690              
691 31         350 my($code) = $super->can($method);
692              
693 31 50       116 die "Can not find method '$method' in Module::Info" unless $code;
694              
695 31         252 goto &$code;
696             }
697              
698             =item B
699              
700             $module->use_version(0); # do not use version.pm (default)
701             $module->use_version(1); # use version.pm, die if not present
702             my $flag = $module->use_version;
703              
704             Sets/gets the "use_version" flag. When the flag is enabled the 'version'
705             method always returns a version object.
706              
707             =cut
708              
709             sub use_version {
710 18     18 1 42 my($self) = shift;
711              
712 18 100       45 if( @_ ) {
713 2 50 33     10 die "Can not use 'version.pm' as requested"
714             if $_[0] && !$has_version_pm;
715              
716 2 50       6 $self->{use_version} = $_[0] ? 1 : 0;
717             }
718              
719 18         131 return $self->{use_version};
720             }
721              
722             =back
723              
724             =head1 AUTHOR
725              
726             Michael G Schwern with code from ExtUtils::MM_Unix,
727             Module::InstalledVersion and lots of cargo-culting from B::Deparse.
728              
729             Mattia Barbon is the current maintainer.
730              
731             =head1 LICENSE
732              
733             This program is free software; you can redistribute it and/or
734             modify it under the same terms as Perl itself.
735              
736             =head1 THANKS
737              
738             Many thanks to Simon Cozens and Robin Houston for letting me chew
739             their ears about B.
740              
741             =head1 CAVEATS
742              
743             Code refs in @INC are currently ignored. If this bothers you submit a
744             patch.
745              
746             superclasses() is cheating and just loading the module in a separate
747             process and looking at @ISA. I don't think its worth the trouble to
748             go through and parse the opcode tree as it still requires loading the
749             module and running all the BEGIN blocks. Patches welcome.
750              
751             I originally was going to call superclasses() isa() but then I
752             remembered that would be bad.
753              
754             All the methods that require loading are really inefficient as they're
755             not caching anything. I'll worry about efficiency later.
756              
757             =cut
758              
759             package Module::Info::Safe;
760              
761             my $root = 'Module::Info::Safe::_safe';
762              
763             sub _create_compartment {
764 2     2   21 my $safe = Safe->new( $root );
765              
766 2         2662 $safe->permit_only( qw(:base_orig :base_core) );
767              
768 2         26 return $safe;
769             }
770              
771             sub _eval {
772 2     2   5 my($self, $code) = @_;
773 2   33     12 $self->{compartment} ||= _create_compartment;
774              
775 2         11 return $self->{compartment}->reval( $code, 0 )
776             }
777              
778             sub _call_perl {
779 0     0   0 die "Module::Info attemped an unsafe operation while in 'safe' mode.";
780             }
781              
782             package Module::Info::Unsafe;
783              
784 3     3   21 sub _eval { eval($_[1]) }
  3     3   6  
  3     2   170  
  3     2   15  
  3     2   4  
  3     2   78  
  2     2   21  
  2     2   55  
  2     11   224  
  2         15  
  2         5  
  2         68  
  2         10  
  2         4  
  2         95  
  2         12  
  2         2  
  2         59  
  2         11  
  2         4  
  2         107  
  2         13  
  2         3  
  2         55  
  11         968  
785              
786             sub _is_win95() {
787 18   33 18   166 return $^O eq 'MSWin32' && (Win32::GetOSVersion())[4] == 1;
788             }
789              
790             sub _is_macos_classic() {
791 36     36   269 return $^O eq 'MacOS';
792             }
793              
794             sub _call_perl {
795 18     18   55 my($self, $args) = @_;
796              
797 18 50       64 my $perl = _is_macos_classic ? 'perl' : $^X;
798 18         90 my $command = "$perl $args";
799 18         43 my @out;
800              
801 18 50       67 if( _is_win95 ) {
    50          
802 0         0 require IPC::Open3;
803 0         0 local *OUTFH;
804 0         0 my($line, $in);
805 0         0 my $out = \*OUTFH;
806 0         0 my $pid = IPC::Open3::open3($in, $out, $out, $command);
807 0         0 close $in;
808 0         0 while( defined($line = ) ) {
809 0         0 $line =~ s/\r\n$/\n/; # strip CRs
810 0         0 push @out, $line;
811             }
812              
813 0         0 waitpid $pid, 0;
814             }
815             elsif( _is_macos_classic ) {
816 0         0 @out = `$command \xb7 Dev:Stdout`;
817             }
818             else {
819 18         4027816 @out = `$command 2>&1`;
820             }
821              
822 18         3139 @out = grep !/^Using.*blib$/, @out;
823 18         1870 return ($?, @out);
824             }
825              
826             return 'Stepping on toes is what Schwerns do best! *poing poing poing*';