lib/FP/Repl/StackPlus.pm

filter: Statementstmt 56.2% 27 / 48 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 1 totaltotal 52.3% 34 / 65 CC 4 SCAR 14.8
CC
4
Cov
50%
__ANON__
12.0
get
6.0
equal
2.0
CRAP 4.4
« lib/Chj/Backtrace.pm ↑ Summary lib/Chj/Unix/Exitcode.pm »
1 #
2 # Copyright (c) 2015 Christian Jaeger, copying@christianjaeger.ch
3 #
4 # This is free software, offered under either the same terms as perl 5
5 # or the terms of the Artistic License version 2 or the terms of the
6 # MIT License (Expat version). See the file COPYING.md that came
7 # bundled with this file.
8 #
9  
10 =head1 NAME
11  
12 FP::Repl::StackPlus - Stack including lexical variables
13  
14 =head1 SYNOPSIS
15  
16 my $stack = FP::Repl::StackPlus->get($numbers_of_levels_to_skip);
17 # same as FP::Repl::Stack, but frames also have `lexicals`, a hash
18 # as delivered from PadWalker
19  
20 =head1 DESCRIPTION
21  
22 I'm pretty sure this is still re-inventing some wheel...
23  
24 =head1 SEE ALSO
25  
26 L<FP::Repl::Stack>, L<PadWalker>
27  
28 =head1 NOTE
29  
30 This is alpha software! Read the status section in the package README
31 or on the L<website|http://functional-perl.org/>.
32  
33 =cut
34  
35 package FP::Repl::StackPlus;
36  
37 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 {
42  
43 1 package FP::Repl::Repl::StackPlusFrame;
44  
45 1 ▶ use FP::Repl::Stack; # so that FP::Struct won't try to load
Subroutine BEGIN: called CC=1 SCAR=0.0
46 # FP/Repl/StackFrame.pm
47  
48 1 ▶ use FP::Struct ["lexicals"], "FP::Repl::StackFrame";
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 # CAREFUL: equal stackframes still don't need to be the *same*
51 # stackframe!
52 0 ▶ sub equal {
Subroutine equal: not called CC=1 SCAR=6.9
53 0 my $s = shift;
54 0 my ($v) = @_;
55 0 die "not implemented (yet?)";
56 }
57  
58 1 _END_
59 }
60  
61 1 ▶use PadWalker qw(peek_my);
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 # TODO/XXX: see comments in commit 'StackPlus: don't die in peek_my
64 # (HACK)'; this should be replaced with something clean /
65 # investigated.
66 0 ▶our $maybe_peek_my = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
67 0 my ($skip) = @_;
68 0 my $res;
69 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $res = peek_my($skip); 1 } }) { } 0 0 0
70 eval {
71 0 $res = peek_my($skip);
72 0 1
73 }
74 )
75 {
76 0 $res
77 } else {
78 0 my $e = $@;
79 0 ▶ if ($e =~ /^Not nested deeply enough/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /^Not nested deeply enough/i) { } 0 0 0
80 undef
81 0 } else {
82 0 die $e
83 }
84 }
85 1 };
86  
87 1 ▶use FP::Struct [], "FP::Repl::Stack";
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 # XX ugly, modified COPY from FP::Repl::Stack
90 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod undocumented
91 0 my $class = shift;
92 0 my ($skip) = @_;
93  
94 package DB; # needs to be outside loop or it won't work. Wow Perl.
95 0 my @frames;
96 0 ▶ while (my @vals = caller($skip)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@vals) = caller $skip) 0 0 0
97 0 my $subargs = [@DB::args];
98  
99 # XX how to handle this?: "@DB::args might have
100 # information from the previous time "caller" was
101 # called" (perlfunc on 'caller')
102 0 push @frames,
103 FP::Repl::Repl::StackPlusFrame->new($subargs, @vals,
104 &$maybe_peek_my($skip + 2));
105 0 $skip++;
106 }
107 0 $class->new(\@frames);
108 }
109  
110 1 *lexicals = &$FP::Repl::Stack::make_frame_accessor("lexicals");
111 1 *perhaps_lexicals = &$FP::Repl::Stack::make_perhaps_frame_accessor("lexicals");
112  
113 1 _END_
« lib/Chj/Backtrace.pm ↑ Summary lib/Chj/Unix/Exitcode.pm »