| 1 | 1 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package Pry; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.003001'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Exporter::Shiny our @EXPORT = qw(pry); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # cargo-culted Win32 stuff... untested! | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | require Term::ANSIColor; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | require Win32::Console::ANSI; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | Win32::Console::ANSI->import; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | our ($Lexicals, $Trace, $Already); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # a refinement for the Reply class | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $_say = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | require Term::ANSIColor; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my ($text, $colour) = (@_, "cyan"); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | print Term::ANSIColor::colored($text, "bold $colour"), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | our $Dumper = 'Data::Dumper'; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $_display_vars = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $invocant = shift; | |||||||||||||||||||||||||||||||||||||||||
| 37 | my $_dumper = $Dumper eq 'Data::Dump' | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ? do { require Data::Dump; \&Data::Dump::dump } | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | : do { require Data::Dumper; \&Data::Dumper::Dumper }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | local $Data::Dumper::Deparse = 1; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | for my $var (@_) | |||||||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $val = ($var =~ /\A\$/) ? ${$Lexicals->{$var}} : $Lexicals->{$var}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $dump = $_dumper->($val); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | chomp($dump); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $dump =~ s/(\A\[)/\(/ and $dump =~ s/(\]\z)/\)/ if $var =~ /\A\@/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$var =~ /\A\@/ && ($dump =~ s/(\A\[)/(/ && $dump =~ s/(\]\z)/)/)
$dump =~ s/(\A\[)/(/ and $dump =~ s/(\]\z)/)/
MC/DC0%0/3
$var =~ /\A\@/ && ($dump =~ s/(\A\[)/(/ && $dump =~ s/(\]\z)/)/)
$var =~ /\A\@/
$dump =~ s/(\A\[)/(/
$dump =~ s/(\]\z)/)/
Truth table0%0/4
A && B and C
A= $var =~ /\A\@/B= $dump =~ s/(\A\[)/(/C= $dump =~ s/(\]\z)/)/
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $dump =~ s/(\A\{)/\(/ and $dump =~ s/(\}\z)/\)/ if $var =~ /\A\%/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$var =~ /\A\%/ && ($dump =~ s/(\A\{)/(/ && $dump =~ s/(\}\z)/)/)
$dump =~ s/(\A\{)/(/ and $dump =~ s/(\}\z)/)/
MC/DC0%0/3
$var =~ /\A\%/ && ($dump =~ s/(\A\{)/(/ && $dump =~ s/(\}\z)/)/)
$var =~ /\A\%/
$dump =~ s/(\A\{)/(/
$dump =~ s/(\}\z)/)/
Truth table0%0/4
A && B and C
A= $var =~ /\A\%/B= $dump =~ s/(\A\{)/(/C= $dump =~ s/(\}\z)/)/
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $invocant->$_say("$var = $dump;", "yellow"); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # shim to pass lexicals to Reply | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | package #hide | |||||||||||||||||||||||||||||||||||||||||
| 59 | Pry::_Lexicals; | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | our @ISA = qw( Reply::Plugin ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub lexical_environment { $Lexicals } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lexical_environment: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | $INC{'Pry/_Lexicals.pm'} = __FILE__; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # the guts | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # | ||||||||||||||||||||||||||||||||||||||||||
| 67 | sub pry (;@) | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pry: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($caller, $file, $line) = caller; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( $Already ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | Reply->$_say( | |||||||||||||||||||||||||||||||||||||||||
| 74 | "Pry is not re-entrant; not prying again at $file line $line", | ||||||||||||||||||||||||||||||||||||||||||
| 75 | "magenta", | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | local $Already = 1; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | require Devel::StackTrace; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | require Reply; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | require PadWalker; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | $Lexicals = +{ | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | %{ PadWalker::peek_our(1) }, | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | %{ PadWalker::peek_my(1) }, | |||||||||||||||||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $Trace = Devel::StackTrace->new( | |||||||||||||||||||||||||||||||||||||||||
| 90 | ignore_package => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | message => "Prying", | ||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $repl = Reply->new( | |||||||||||||||||||||||||||||||||||||||||
| 95 | config => ".replyrc", | ||||||||||||||||||||||||||||||||||||||||||
| 96 | plugins => [ "/Pry/_Lexicals" ], | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $repl->step("package $caller"); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $repl->$_say("Prying at $file line $line", "magenta"); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $repl->$_display_vars(@_) if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $repl->$_say("Current package: '$caller'"); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $repl->$_say("Lexicals in scope: @{[ sort keys %$Lexicals ]}"); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $repl->$_say("Ctrl+D to finish prying.", "magenta"); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $repl->run; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $repl->$_say("Finished prying!", "magenta"); | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my @return = map($Lexicals->{$_}, @_); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | wantarray ? @return : \@return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # utils | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub Lexicals () { $Lexicals if $] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Lexicals: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub Trace () { $Trace if $] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Trace: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub Dump (@) { __PACKAGE__->$_display_vars(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||