File Coverage

blib/lib/Devel/Wherefore.pm
Criterion Covered Total %
statement 18 25 72.0
branch 0 4 0.0
condition n/a
subroutine 6 7 85.7
pod n/a
total 24 36 66.6


line stmt bran cond sub pod time code
1             package Devel::Wherefore;
2              
3             our $VERSION = '0.000003'; # v0.0.3
4              
5             $VERSION = eval $VERSION;
6              
7 1     1   520 use strict;
  1         2  
  1         30  
8 1     1   5 use warnings;
  1         2  
  1         23  
9 1     1   6 use B ();
  1         2  
  1         19  
10 1     1   471 use Sub::Identify qw(sub_fullname get_code_location);
  1         1068  
  1         65  
11 1     1   487 use Package::Stash;
  1         8277  
  1         39  
12 1     1   495 use Data::Munge qw(list2re);
  1         1632  
  1         451  
13              
14             # detect -d:Wherefore and disable debugger features
15             if (!defined &DB::DB && $^P & 0x02) {
16             $^P = 0;
17             }
18              
19             sub import {
20 0     0     our (undef, $pkg) = @_;
21 0 0         unless ($pkg) {
22 0           my $prefix = list2re @INC, 'lib';
23 0 0         if (my ($path) = $0 =~ m{^(?:${prefix}/)?(.*)\.pm$}) {
24 0           $pkg = join '::', split '/', $path;
25             } else {
26 0           $pkg = 'main';
27             }
28             }
29 0           B::minus_c;
30             }
31              
32             sub CHECK {
33             return unless our $pkg;
34             my $subs = Package::Stash->new($pkg)->get_all_symbols('CODE');
35             print "# Symbols found in package ${pkg} after compiling $0\n";
36             foreach my $name (sort keys %$subs) {
37             my $fullname = sub_fullname $subs->{$name};
38             my ($file, $line) = get_code_location $subs->{$name};
39             print join("\t",
40             map +(defined() ? $_ : "\\N"), ${name}, ${fullname}, ${file}, ${line}
41             )."\n";
42             }
43             close(STDERR);
44             }
45              
46             1;
47              
48             =head1 NAME
49              
50             Devel::Wherefore - Where the heck did these subroutines come from?
51              
52             =head1 SYNOPSIS
53              
54             $ perl -d:Wherefore myscript.pl
55              
56             will dump symbols in main from myscript.pl
57              
58             $ perl -d:Wherefore=App::opan $(which opan)
59              
60             will dump symbols from package App::opan in the installed opan script
61              
62             $ perl -d:Wherefore lib/Foo/Bar.pm
63              
64             will dump symbols from package Foo::Bar (we guess the package by stripping
65             either 'lib' or any @INC entry off the front, then assuming the package
66             name is Foo::Bar for Foo/Bar.pm etc). Which means this also works:
67              
68             $ perl -d:Wherefore $(perldoc -lm App::Cpan)
69              
70             Note that this code uses C to only compile the script so you
71             don't have to worry about it executing - does mean we'll miss runtime
72             require and import but hey, trade-offs.
73              
74             =head1 DESCRIPTION
75              
76             Rage driven development rapidly released.
77              
78             =head1 AUTHOR
79              
80             mst - Matt S. Trout (cpan:MSTROUT)
81              
82             =head1 CONTRIBUTORS
83              
84             None yet - maybe this software is perfect! (ahahahahahahahahaha)
85              
86             =head1 COPYRIGHT
87              
88             Copyright (c) 2020 the Devel::Wherefore L and L
89             as listed above.
90              
91             =head1 LICENSE
92              
93             This library is free software and may be distributed under the same terms
94             as perl itself.