Sepia.pm

filter: Statementstmt 19.9% 212 / 1062 Branchbran 9.8% 42 / 426 Conditioncond 10.1% 22 / 217 MC/DCmcdc 5.9% 7 / 117 Subroutinesub 35.5% 53 / 149 Podpod 51.1% 43 / 84 totaltotal 18.4% 379 / 2055 CC 324 SCAR 45.0
CC
324
Cov
16%
repl
552.0
html_module_list
506.0
who
205.2
CRAP 89.6
↑ Summary Sepia/Xref.pm »
1 package Sepia;
2  
3 =head1 NAME
4  
5 Sepia - Simple Emacs-Perl Interface
6  
7 =head1 SYNOPSIS
8  
9 From inside Emacs:
10  
11 M-x load-library RET sepia RET
12 M-x sepia-repl RET
13  
14 At the prompt in the C<*sepia-repl*> buffer:
15  
16 main @> ,help
17  
18 For more information, please see F<Sepia.html> or F<sepia.info>, which
19 come with the distribution.
20  
21 =head1 DESCRIPTION
22  
23 Sepia is a set of features to make Emacs a better tool for Perl
24 development. This package contains the Perl side of the
25 implementation, including all user-serviceable parts (for the
26 cross-referencing facility see L<Sepia::Xref>). This document is
27 aimed as Sepia developers; for user documentation, see
28 L<Sepia.html> or L<sepia.info>.
29  
30 Though not intended to be used independent of the Emacs interface, the
31 Sepia module's functionality can be used through a rough procedural
32 interface.
33  
34 =cut
35  
36 2 $VERSION = '0.992_01';
37 2 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=14.2
38 2 ▶ if ($] >= 5.012) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.012") 2 0 2
39 2 ▶ eval 'no warnings "deprecated"'; # undo some of the 5.12 suck.
Subroutine BEGIN: called CC=1 SCAR=0.0
40 }
41 # Not as useful as I had hoped...
42 sub track_requires
43 0 ▶ {
Subroutine track_requires: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my $parent = caller;
45 0 (my $child = $_[1]) =~ s!/!::!g;
46 0 $child =~ s/\.pm$//;
47 0 push @{$REQUIRED_BY{$child}}, $parent;
48 0 push @{$REQUIRES{$parent}}, $child;
49 }
50 2 ▶ BEGIN { sub TRACK_REQUIRES () { $ENV{TRACK_REQUIRES}||0 } };
Subroutine TRACK_REQUIRES: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"TRACK_REQUIRES"} or 0 0 2 2
51 2 ▶ unshift @INC, \&Sepia::track_requires if TRACK_REQUIRES;
Branch: 1 branch
BranchTrueFalseTotal
if &TRACK_REQUIRES() 0 2 2
52 }
53 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 2 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 2 ▶use Sepia::Debug; # THIS TURNS ON DEBUGGING INFORMATION!
Subroutine BEGIN: called CC=1 SCAR=0.0
56 2 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
57 2 ▶use Scalar::Util 'looks_like_number';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 ▶use Text::Abbrev;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 2 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 2 ▶use Storable qw(store retrieve);
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 2 ▶use vars qw($PS1 %REPL %RK %REPL_DOC %REPL_SHORT %PRINTER
Subroutine BEGIN: called CC=1 SCAR=0.0
63 @res $REPL_LEVEL $REPL_QUIT $PACKAGE $SIGGED
64 $WANTARRAY $PRINTER $STRICT $COLUMNATE $ISEVAL $STRINGIFY
65 $LAST_INPUT $READLINE @PRE_EVAL @POST_EVAL @PRE_PROMPT
66 2 %REQUIRED_BY %REQUIRES);
67  
68 2 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=10.1
69 2 ▶ eval q{ use List::Util 'max' };
Subroutine BEGIN: called CC=1 SCAR=0.0
70 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
71 0 ▶ *Sepia::max = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
72 0 my $ret = shift;
73 0 for (@_) {
74 0 ▶ $ret = $_ if $_ > $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $_ > $ret 0 0 0
75 }
76 0 $ret;
77 0 };
78 }
79 }
80  
81 =head2 Hooks
82  
83 Like Emacs, Sepia's behavior can be modified by placing functions on
84 various hooks (arrays). Hooks can be manipulated by the following
85 functions:
86  
87 =over
88  
89 =item C<add_hook(@hook, @functions)> -- Add C<@functions> to C<@hook>.
90  
91 =item C<remove_hook(@hook, @functions)> -- Remove named C<@functions> from C<@hook>.
92  
93 =item C<run_hook(@hook)> -- Run the functions on the named hook.
94  
95 Each function is called with no arguments in an eval {} block, and
96 its return value is ignored.
97  
98 =back
99  
100 Sepia currently defines the following hooks:
101  
102 =over
103  
104 =item C<@PRE_PROMPT> -- Called immediately before the prompt is printed.
105  
106 =item C<@PRE_EVAL> -- Called immediately before evaluating user input.
107  
108 =item C<@POST_EVAL> -- Called immediately after evaluating user input.
109  
110 =back
111  
112 =cut
113  
114 sub run_hook(\@)
115 0 ▶{
Subroutine run_hook: not called CC=2 SCAR=10.1
Pod documented
116 0 my $hook = shift;
117 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
118 0 for (@$hook) {
119 0 eval { $_->() };
120 }
121 }
122  
123 sub add_hook(\@@)
124 0 ▶{
Subroutine add_hook: not called CC=3 SCAR=24.8
Pod documented
125 0 my $hook = shift;
126 0 for my $h (@_) {
127 0 ▶ push @$hook, $h unless grep $h eq $_, @$hook;
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($h eq $_), @$hook) 0 0 0
128 }
129 }
130  
131 sub remove_hook(\@@)
132 0 ▶{
Subroutine remove_hook: not called CC=1 SCAR=6.9
Pod documented
133 0 my $hook = shift;
134 0 @$hook = grep { my $x = $_; !grep $_ eq $x, @$hook } @$hook;
135 }
136  
137 =head2 Completion
138  
139 Sepia tries hard to come up with a list of completions.
140  
141 =over
142  
143 =item C<$re = _apropos_re($pat)>
144  
145 Create a completion expression from user input.
146  
147 =cut
148  
149 sub _apropos_re($;$)
150 0 ▶{
Subroutine _apropos_re: not called CC=5 SCAR=34.0
151 # Do that crazy multi-word identifier completion thing:
152 0 my $re = shift;
153 0 ▶ my $hat = shift() ? '' : '^';
Branch: 1 branch
BranchTrueFalseTotal
shift() ? : 0 0 0
154 0 ▶ return qr/.*/ if $re eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $re eq "" 0 0 0
155 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
156 map {
157 0 s/(?:^|(?<=[A-Za-z\d]))(([^A-Za-z\d])\2*)/[A-Za-z\\d]*$2+/g;
158 0 qr/$hat$_/;
159 } split /:+/, $re, -1;
160 } else {
161 0 ▶ if ($re !~ /[^\w\d_^:]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($re =~ /[^\w\d_^:]/) 0 0 0
162 0 $re =~ s/(?<=[A-Za-z\d])(([^A-Za-z\d])\2*)/[A-Za-z\\d]*$2+/g;
163 }
164 0 qr/$re/;
165 }
166 }
167  
168 2 my %sigil;
169 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
170 2 %sigil = qw(ARRAY @ SCALAR $ HASH %);
171 }
172  
173 =item C<$val = filter_untyped>
174  
175 Return true if C<$_> is the name of a sub, file handle, or package.
176  
177 =item C<$val = filter_typed $type>
178  
179 Return true if C<$_> is the name of something of C<$type>, which
180 should be either a glob slot name (e.g. SCALAR) or the special value
181 "VARIABLE", meaning an array, hash, or scalar.
182  
183 =cut
184  
185  
186 sub filter_untyped
187 4 ▶{
Subroutine filter_untyped: called CC=5 SCAR=20.9
Pod documented
188 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 4 ▶ local $_ = /^::/ ? $_ : "::$_";
Branch: 1 branch
BranchTrueFalseTotal
/^::/ ? : 0 4 4
190 0 ▶ defined *{$_}{CODE} || defined *{$_}{IO} || (/::$/ && %$_);
Branch: 1 branch
BranchTrueFalseTotal
defined *{$_;}{"CODE"} or defined *{$_;}{"IO"} or /::$/ and %$_ 0 4 4
Condition33%3/9
defined *{$_;}{'CODE'} || defined *{$_;}{'IO'} || /::$/ && %$_
l!l&&r!l&&!r
040
defined *{$_;}{"CODE"} or defined *{$_;}{"IO"}
l!l&&r!l&&!r
004
/::$/ and %$_
!ll&&!rl&&r
004
MC/DC0%0/4
defined *{$_;}{'CODE'} || defined *{$_;}{'IO'} || /::$/ && %$_
defined *{$_;}{"CODE"} defined *{$_;}{"IO"} /::$/ %$_
Truth table20%1/5
A or B || C and D
A= defined *{$_;}{"CODE"}B= defined *{$_;}{"IO"}C= /::$/D= %$_
ABCDresult
1XXX1
01XX1
00111
000X0
00100
191 }
192  
193 ## XXX: Careful about autovivification here! Specifically:
194 ## defined *FOO{HASH} # => ''
195 ## defined %FOO # => ''
196 ## defined *FOO{HASH} # => 1
197 sub filter_typed
198 86 ▶{
Subroutine filter_typed: called CC=6 SCAR=24.1
Pod documented
199 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
200 86 my $type = shift;
201 86 ▶ local $_ = /^::/ ? $_ : "::$_";
Branch: 1 branch
BranchTrueFalseTotal
/^::/ ? : 0 86 86
202 86 ▶ if ($type eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'SCALAR') { } 6 80 86
elsif ($type eq 'VARIABLE') { } 0 80 80
203 0 defined $$_;
204 } elsif ($type eq 'VARIABLE') {
205 0 ▶ defined $$_ || defined *{$_}{HASH} || defined *{$_}{ARRAY};
Branch: 1 branch
BranchTrueFalseTotal
defined $$_ or defined *{$_;}{"HASH"} or defined *{$_;}{"ARRAY"} 0 0 0
Condition0%0/3
defined $$_ or defined *{$_;}{"HASH"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $$_ or defined *{$_;}{"HASH"}
defined $$_ defined *{$_;}{"HASH"}
Truth table0%0/3
A or B
A= defined $$_B= defined *{$_;}{"HASH"}
ABresult
1X1
011
000
206 } else {
207 0 defined *{$_}{$type}
208 }
209 }
210  
211 =item C<$re_out = maybe_icase $re_in>
212  
213 Make C<$re_in> case-insensitive if it looks like it should be.
214  
215 =cut
216  
217 sub maybe_icase
218 25 ▶{
Subroutine maybe_icase: called CC=3 SCAR=11.7
Pod documented
219 25 my $ch = shift;
220 25 ▶ return '' if $ch eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "" 0 25 25
221 25 ▶ $ch =~ /[A-Z]/ ? $ch : '['.uc($ch).$ch.']';
Branch: 1 branch
BranchTrueFalseTotal
$ch =~ /[A-Z]/ ? : 0 25 25
222 }
223  
224 =item C<@res = all_abbrev_completions $pattern>
225  
226 Find all "abbreviated completions" for $pattern.
227  
228 =cut
229  
230 sub all_abbrev_completions
231 2 ▶{
Subroutine all_abbrev_completions: called CC=1 SCAR=0.0
Pod documented
232 2 ▶ use vars '&_completions';
Subroutine BEGIN: called CC=1 SCAR=0.0
233 10 ▶ local *_completions = sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
234 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
235 10 my ($stash, @e) = @_;
236 10 my $ch = '[A-Za-z0-9]*';
237 my $re1 = "^".maybe_icase($e[0]).$ch.join('', map {
238 10 '_'.maybe_icase($_).$ch
239 } @e[1..$#e]);
240 10 $re1 = qr/$re1/;
241 10 my $re2 = maybe_icase $e[0];
242 10 $re2 = qr/^$re2.*::$/;
243 0 ▶ my @ret = grep !/::$/ && /$re1/, keys %{$stash};
Condition100%3/3
!/::$/ && /$re1/
!ll&&!rl&&r
17140310
MC/DC100%2/2
!/::$/ && /$re1/
!/::$/ /$re1/
Truth table100%3/3
not(A) && B
A= !/::$/B= /$re1/
ABresult
0X0
100
111
244 0 my @pkgs = grep /$re2/, keys %{$stash};
245 (map("$stash$_", @ret),
246 0 @e > 1 ? map { _completions "$stash$_", @e[1..$#e] } @pkgs :
247 0 ▶ map { "$stash$_" } @pkgs)
Branch: 1 branch
BranchTrueFalseTotal
@e > 1 ? : 4 6 10
248 2 };
249 2 map { s/^:://; $_ } _completions('::', split //, shift);
250 }
251  
252 sub apropos_re
253 14 ▶{
Subroutine apropos_re: called CC=2 SCAR=6.9
Pod undocumented
254 14 my ($icase, $re) = @_;
255 14 $re =~ s/_/[^_]*_/g;
256 14 ▶ $icase ? qr/^$re.*$/i : qr/^$re.*$/;
Branch: 1 branch
BranchTrueFalseTotal
$icase ? : 6 8 14
257 }
258  
259 sub all_completions
260 14 ▶{
Subroutine all_completions: called CC=1 SCAR=0.0
Pod undocumented
261 14 my $icase = $_[0] !~ /[A-Z]/;
262 14 my @parts = split /:+/, shift, -1;
263 14 my $re = apropos_re $icase, pop @parts;
264 2 ▶ use vars '&_completions';
Subroutine BEGIN: called CC=1 SCAR=0.0
265 80 ▶ local *_completions = sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
266 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
267 80 my $stash = shift;
268 80 ▶ if (@_ == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 0) { } 45 35 80
269 0 map { "$stash$_" } grep /$re/, keys %{$stash};
270 } else {
271 35 ▶ my $re2 = $icase ? qr/^$_[0].*::$/i : qr/^$_[0].*::$/;
Branch: 1 branch
BranchTrueFalseTotal
$icase ? : 12 23 35
272 0 my @pkgs = grep /$re2/, keys %{$stash};
273 0 map { _completions "$stash$_", @_[1..$#_] } @pkgs
274 }
275 14 };
276 14 map { s/^:://; $_ } _completions('::', @parts);
277 }
278  
279 =item C<@res = filter_exact_prefix @names>
280  
281 Filter exact matches so that e.g. "A::x" completes to "A::xx" when
282 both "Ay::xx" and "A::xx" exist.
283  
284 =cut
285  
286 sub filter_exact_prefix
287 14 ▶{
Subroutine filter_exact_prefix: called CC=3 SCAR=11.0
Pod documented
288 14 my @parts = split /:+/, shift, -1;
289 14 my @res = @_;
290 14 my @tmp;
291 14 my $pre = shift @parts;
292 14 ▶ while (@parts && (@tmp = grep /^\Q$pre\E(?:::|$)/, @res)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts and @tmp = grep(/^\Q$pre\E(?:::|$)/, @res)) 12 14 26
Condition100%3/3
@parts and @tmp = grep(/^\Q$pre\E(?:::|$)/, @res)
!ll&&!rl&&r
8612
MC/DC100%2/2
@parts and @tmp = grep(/^\Q$pre\E(?:::|$)/, @res)
@parts @tmp = grep(/^\Q$pre\E(?:::|$)/, @res)
Truth table100%3/3
A and B
A= @partsB= @tmp = grep(/^\Q$pre\E(?:::|$)/, @res)
ABresult
0X0
100
111
293 12 @res = @tmp;
294 12 $pre .= '::'.shift @parts;
295 }
296 14 @res;
297 }
298  
299 =item C<@res = lexical_completions $type, $str, $sub>
300  
301 Find lexicals of C<$sub> (or a parent lexical environment) of type
302 C<$type> matching C<$str>.
303  
304 =cut
305  
306 sub lexical_completions
307 0 ▶{
Subroutine lexical_completions: not called CC=2 SCAR=15.7
Pod documented
308 0 eval q{ use PadWalker 'peek_sub' };
309 # "internal" function, so don't warn on failure
310 0 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
311 0 ▶ *lexical_completions = sub {
Subroutine __ANON__: not called CC=4 SCAR=26.4
312 0 my ($type, $str, $sub) = @_;
313 0 ▶ $sub = "$PACKAGE\::$sub" unless $sub =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sub =~ /::/ 0 0 0
314 # warn "Completing $str of type $type in $sub\n";
315 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
316 0 ▶ return unless defined *{$sub}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
unless defined *{$sub;}{"CODE"} 0 0 0
317 0 my $pad = peek_sub(\&$sub);
318 0 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 0 0 0
319 0 map { s/^[\$\@&\%]//;$_ } grep /^\Q$type$str\E/, keys %$pad;
320 } else {
321 0 map { s/^[\$\@&\%]//;$_ } grep /^.\Q$str\E/, keys %$pad;
322 }
323 0 };
324 0 goto &lexical_completions;
325 }
326  
327 =item C<@compls = completions($string [, $type [, $sub ] ])>
328  
329 Find a list of completions for C<$string> with glob type C<$type>,
330 which may be "SCALAR", "HASH", "ARRAY", "CODE", "IO", or the special
331 value "VARIABLE", which means either scalar, hash, or array.
332 Completion operates on word subparts separated by [:_], so
333 e.g. "S:m_w" completes to "Sepia::my_walksymtable". If C<$sub> is
334 given, also consider its lexical variables.
335  
336 =item C<@compls = method_completions($expr, $string [,$eval])>
337  
338 Complete among methods on the object returned by C<$expr>. The
339 C<$eval> argument, if present, is a function used to do the
340 evaluation; the default is C<eval>, but for example the Sepia REPL
341 uses C<Sepia::repl_eval>. B<Warning>: Since it has to evaluate
342 C<$expr>, method completion can be extremely problematic. Use with
343 care.
344  
345 =cut
346  
347 sub completions
348 14 ▶{
Subroutine completions: called CC=14 SCAR=30.8
Pod documented
349 14 my ($type, $str, $sub) = @_;
350 14 my $t;
351 14 my %h = qw(@ ARRAY % HASH & CODE * IO $ SCALAR);
352 14 my %rh;
353 14 @rh{values %h} = keys %h;
354 14 ▶ $type ||= '';
Condition100%2/2
$type ||= ""
l!l
131
MC/DC100%1/1
$type ||= ""
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
355 14 ▶ $t = $type ? $rh{$type} : '';
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 13 1 14
356 14 my @ret;
357 14 ▶ if ($sub && $type ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub and $type ne "") 0 14 14
Condition33%1/3
$sub and $type ne ""
!ll&&!rl&&r
1400
MC/DC0%0/2
$sub and $type ne ""
$sub $type ne ""
Truth table33%1/3
A and B
A= $subB= $type ne ""
ABresult
0X0
100
111
358 0 @ret = lexical_completions $t, $str, $sub;
359 }
360 14 ▶ if (!@ret) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ret) 14 0 14
361 @ret = grep {
362 0 ▶ $type ? filter_typed $type : filter_untyped
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 76 0 76
363 } all_completions $str;
364 }
365 14 ▶ if (!@ret && $str !~ /:/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ret or $str =~ /:/) 2 12 14
Condition100%3/3
@ret or $str =~ /:/
l!l&&r!l&&!r
1112
MC/DC100%2/2
@ret or $str =~ /:/
@ret $str =~ /:/
Truth table100%3/3
A or B
A= @retB= $str =~ /:/
ABresult
1X1
011
000
366 @ret = grep {
367 0 ▶ $type ? filter_typed $type : filter_untyped
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 10 4 14
368 } all_abbrev_completions $str;
369 }
370 14 @ret = map { s/^:://; "$t$_" } filter_exact_prefix $str, @ret;
371 # ## XXX: Control characters, $", and $1, etc. confuse Emacs, so
372 # ## remove them.
373 grep {
374 14 ▶ length $_ > 0 && !/^\d+$/ && !/^[^\w\d_]$/ && !/^_</ && !/^[[:cntrl:]]/
Condition33%4/12
length $_ > 0 && !/^\d+$/ && !/^[^\w\d_]$/ && !/^_</ && !/^[[:cntrl:]]/
!ll&&!rl&&r
0026
length $_ > 0 and not /^\d+$/ and not /^[^\w\d_]$/ and not /^_</
!ll&&!rl&&r
0026
length $_ > 0 and not /^\d+$/ and not /^[^\w\d_]$/
!ll&&!rl&&r
0026
length $_ > 0 and not /^\d+$/
!ll&&!rl&&r
0026
MC/DC0%0/5
length $_ > 0 && !/^\d+$/ && !/^[^\w\d_]$/ && !/^_</ && !/^[[:cntrl:]]/
length $_ > 0 not /^\d+$/ not /^[^\w\d_]$/ not /^_</ !/^[[:cntrl:]]/
Truth table16%1/6
A and not(B) and not(C) and not(D) && not(E)
A= length $_ > 0B= not /^\d+$/C= not /^[^\w\d_]$/D= not /^_</E= !/^[[:cntrl:]]/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
375 } @ret;
376 }
377  
378 sub method_completions
379 0 ▶{
Subroutine method_completions: not called CC=8 SCAR=40.3
Pod documented
380 0 my ($x, $fn, $eval) = @_;
381 0 $x =~ s/^\s+//;
382 0 $x =~ s/\s+$//;
383 0 ▶ $eval ||= 'CORE::eval';
Condition0%0/2
$eval ||= "CORE::eval"
l!l
00
MC/DC0%0/1
$eval ||= "CORE::eval"
$eval
Truth table0%0/2
A
A= $eval
Aresult
11
00
384 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
385 0 ▶ return unless ($x =~ /^\$/ && ($x = $eval->("ref($x)")))
Branch: 1 branch
BranchTrueFalseTotal
unless $x =~ /^\$/ and $x = &$eval("ref($x)") or &$eval('%' . $x . '::') 0 0 0
Condition0%0/6
$x =~ /^\$/ and $x = &$eval("ref($x)") or &$eval('%' . $x . '::')
l!l&&r!l&&!r
000
$x =~ /^\$/ and $x = &$eval("ref($x)")
!ll&&!rl&&r
000
MC/DC0%0/3
$x =~ /^\$/ and $x = &$eval("ref($x)") or &$eval('%' . $x . '::')
$x =~ /^\$/ $x = &$eval("ref($x)") &$eval('%' . $x . '::')
Truth table0%0/5
A and B or C
A= $x =~ /^\$/B= $x = &$eval("ref($x)")C= &$eval('%' . $x . '::')
ABCresult
11X1
0X11
1011
0X00
1000
386 || $eval->('%'.$x.'::');
387 0 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
388 0 my $re = _apropos_re $fn;
389 ## Filter out overload methods "(..."
390 0 return sort { $a cmp $b } map { s/.*:://; $_ }
391 0 ▶ grep { defined *{$_}{CODE} && /::$re/ && !/\(/ }
Condition0%0/6
defined *{$_;}{'CODE'} && /::$re/ && !/\(/
!ll&&!rl&&r
000
defined *{$_;}{"CODE"} and /::$re/
!ll&&!rl&&r
000
MC/DC0%0/3
defined *{$_;}{'CODE'} && /::$re/ && !/\(/
defined *{$_;}{"CODE"} /::$re/ !/\(/
Truth table0%0/4
A and B && not(C)
A= defined *{$_;}{"CODE"}B= /::$re/C= !/\(/
ABCresult
0XX0
10X0
1100
1111
392 methods($x, 1);
393 }
394 }
395  
396 =item C<@matches = apropos($name [, $is_regex])>
397  
398 Search for function C<$name>, either in all packages or, if C<$name>
399 is qualified, only in one package. If C<$is_regex> is true, the
400 non-package part of C<$name> is a regular expression.
401  
402 =cut
403  
404 sub my_walksymtable(&*)
405 1 ▶{
Subroutine my_walksymtable: called CC=1 SCAR=0.0
Pod undocumented
406 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
407 1 my ($f, $st) = @_;
408 299 ▶ local *_walk = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
409 299 local ($stash) = @_;
410 299 &$f for keys %$stash;
411 299 _walk("$stash$_") for grep /(?<!main)::$/, keys %$stash;
412 1 };
413 1 _walk($st);
414 }
415  
416 sub apropos
417 1 ▶{
Subroutine apropos: called CC=11 SCAR=36.9
Pod documented
418 1 my ($it, $re, @types) = @_;
419 1 my $stashp;
420 1 ▶ if (@types) {
Branch: 1 branch
BranchTrueFalseTotal
if (@types) { } 0 1 1
421 0 $stashp = grep /STASH/, @types;
422 0 @types = grep !/STASH/, @types;
423 } else {
424 1 @types = qw(CODE);
425 }
426 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
427 1 ▶ if ($it =~ /^(.*::)([^:]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it =~ /^(.*::)([^:]+)$/) { } 0 1 1
428 0 my ($stash, $name) = ($1, $2);
429 0 ▶ if (!%$stash) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%$stash) 0 0 0
430 0 return;
431 }
432 0 ▶ if ($re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re) { } 0 0 0
433 0 my $name = qr/^$name/;
434 map {
435 0 "$stash$_"
436 }
437 grep {
438 0 my $stashnm = "$stash$_";
439 /$name/ &&
440 (($stashp && /::$/)
441 || scalar grep {
442 0 ▶ defined($_ eq 'SCALAR' ? $$stashnm : *{$stashnm}{$_})
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'SCALAR' ? : 0 0 0
Condition0%0/8
/$name/ && ($stashp && /::$/ || scalar grep({defined($_ eq 'SCALAR' ? $$stashnm : *{$stashnm;}{$_});} @types))
!ll&&!rl&&r
000
$stashp and /::$/ or scalar grep({defined($_ eq "SCALAR" ? $$stashnm : *{$stashnm;}{$_});} @types)
l!l
00
$stashp and /::$/
!ll&&!rl&&r
000
MC/DC0%0/3
/$name/ && ($stashp && /::$/ || scalar grep({defined($_ eq 'SCALAR' ? $$stashnm : *{$stashnm;}{$_});} @types))
/$name/ $stashp /::$/
Truth table0%0/4
A && B and C
A= /$name/B= $stashpC= /::$/
ABCresult
0XX0
10X0
1100
1111
443 } @types)
444 } keys %$stash;
445 } else {
446 0 ▶ defined &$it ? $it : ();
Branch: 1 branch
BranchTrueFalseTotal
defined &$it ? : 0 0 0
447 }
448 } else {
449 1 my @ret;
450 1 ▶ my $findre = $re ? qr/$it/ : qr/^\Q$it\E$/;
Branch: 1 branch
BranchTrueFalseTotal
$re ? : 0 1 1
451 6379 ▶ my_walksymtable {
Subroutine __ANON__: called CC=2 SCAR=6.9
452 6379 ▶ push @ret, "$stash$_" if /$findre/;
Branch: 1 branch
BranchTrueFalseTotal
if /$findre/ 1 6378 6379
453 1 } '::';
454 1 map { s/^:*(?:main:+)*//;$_ } @ret;
455 }
456 }
457  
458 =back
459  
460 =head2 Module information
461  
462 =over
463  
464 =item C<@names = mod_subs($pack)>
465  
466 Find subs in package C<$pack>.
467  
468 =cut
469  
470 sub mod_subs
471 1 ▶{
Subroutine mod_subs: called CC=2 SCAR=8.3
Pod documented
472 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
473 1 my $p = shift;
474 0 my $stash = \%{"$p\::"};
475 1 ▶ if (%$stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$stash) 1 0 1
476 0 grep { defined &{"$p\::$_"} } keys %$stash;
477 }
478 }
479  
480 =item C<@decls = mod_decls($pack)>
481  
482 Generate a list of declarations for all subroutines in package
483 C<$pack>.
484  
485 =cut
486  
487 sub mod_decls
488 0 ▶{
Subroutine mod_decls: not called CC=3 SCAR=20.3
Pod documented
489 0 my $pack = shift;
490 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
491 my @ret = map {
492 0 my $sn = $_;
493 0 my $proto = prototype(\&{"$pack\::$sn"});
494 0 ▶ $proto = defined($proto) ? "($proto)" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $proto ? : 0 0 0
495 0 "sub $sn $proto;";
496 } mod_subs($pack);
497 0 ▶ return wantarray ? @ret : join '', @ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
498 }
499  
500 =item C<$info = module_info($module, $type)>
501  
502 Emacs-called function to get module information.
503  
504 =cut
505  
506 sub module_info
507 0 ▶{
Subroutine module_info: not called CC=2 SCAR=15.7
Pod documented
508 0 eval q{ require Module::Info; import Module::Info };
509 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
510 0 undef;
511 } else {
512 2 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
513 0 ▶ *module_info = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
514 0 my ($m, $func) = @_;
515 0 my $info;
516 0 ▶ if (-f $m) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $m) { } 0 0 0
517 0 $info = Module::Info->new_from_file($m);
518 } else {
519 0 (my $file = $m) =~ s|::|/|g;
520 0 $file .= '.pm';
521 0 ▶ if (exists $INC{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$file}) { } 0 0 0
522 0 $info = Module::Info->new_from_loaded($m);
523 } else {
524 0 $info = Module::Info->new_from_module($m);
525 }
526 }
527 0 ▶ if ($info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) 0 0 0
528 0 return $info->$func;
529 }
530 0 };
531 0 goto &module_info;
532 }
533 }
534  
535 =item C<$file = mod_file($mod)>
536  
537 Find the likely file owner for module C<$mod>.
538  
539 =cut
540  
541 sub mod_file
542 0 ▶{
Subroutine mod_file: not called CC=4 SCAR=30.0
Pod documented
543 0 my $m = shift;
544 0 $m =~ s/::/\//g;
545 0 ▶ while ($m && !exists $INC{"$m.pm"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m and not exists $INC{"$m.pm"}) 0 0 0
Condition0%0/3
$m and not exists $INC{"$m.pm"}
!ll&&!rl&&r
000
MC/DC0%0/2
$m and not exists $INC{"$m.pm"}
$m not exists $INC{"$m.pm"}
Truth table0%0/3
A and not(B)
A= $mB= not exists $INC{"$m.pm"}
ABresult
0X0
100
111
546 0 $m =~ s#(?:^|/)[^/]+$##;
547 }
548 0 ▶ $m ? $INC{"$m.pm"} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$m ? : 0 0 0
549 }
550  
551 =item C<@mods = package_list>
552  
553 Gather a list of all distributions on the system.
554  
555 =cut
556  
557 2 our $INST;
558 sub inst()
559 0 ▶{
Subroutine inst: not called CC=2 SCAR=17.9
Pod undocumented
560 0 ▶ unless ($INST) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Sepia::INST) 0 0 0
561 0 require ExtUtils::Installed;
562 0 $INST = new ExtUtils::Installed;
563 }
564 0 $INST;
565 }
566  
567 sub package_list
568 0 ▶{
Subroutine package_list: not called CC=1 SCAR=6.9
Pod documented
569 0 sort { $a cmp $b } inst()->modules;
570 }
571  
572 =item C<@mods = module_list>
573  
574 Gather a list of all packages (.pm files, really) installed on the
575 system, grouped by distribution. XXX UNUSED
576  
577 =cut
578  
579 sub inc_re
580 0 ▶{
Subroutine inc_re: not called CC=1 SCAR=6.9
Pod undocumented
581 0 join '|', map quotemeta, sort { length $b <=> length $a } @INC;
582 }
583  
584 sub module_list
585 0 ▶{
Subroutine module_list: not called CC=2 SCAR=17.9
Pod documented
586 0 ▶ @_ = package_list unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
587 0 my $incre = inc_re;
588 0 $incre = qr|(?:$incre)/|;
589 0 my $inst = inst;
590 map {
591 0 [$_, sort map {
592 0 s/$incre\///; s|/|::|g;$_
593 } grep /\.pm$/, $inst->files($_)]
594 } @_;
595 }
596  
597 =item C<@paths = file_list $module>
598  
599 List the absolute paths of all files (except man pages) installed by
600 C<$module>.
601  
602 =cut
603  
604 sub file_list
605 0 ▶{
Subroutine file_list: not called CC=2 SCAR=17.9
Pod documented
606 0 my @ret = eval { grep /\.p(l|m|od)$/, inst->files(shift) };
607 0 ▶ @ret ? @ret : ();
Branch: 1 branch
BranchTrueFalseTotal
@ret ? : 0 0 0
608 }
609  
610 =item C<@mods = doc_list>
611  
612 Gather a list of all documented packages (.?pm files, really)
613 installed on the system, grouped by distribution. XXX UNUSED
614  
615 =back
616  
617 =cut
618  
619 sub doc_list
620 0 ▶{
Subroutine doc_list: not called CC=2 SCAR=17.9
Pod documented
621 0 ▶ @_ = package_list unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
622 0 my $inst = inst;
623 map {
624 0 [$_, sort map {
625 0 s/.*man.\///; s|/|::|g;s/\..?pm//; $_
626 } grep /\..pm$/, $inst->files($_)]
627 } @_;
628 }
629  
630 =head2 Miscellaneous functions
631  
632 =over
633  
634 =item C<$v = core_version($module)>
635  
636 =cut
637  
638 sub core_version
639 0 ▶{
Subroutine core_version: not called CC=2 SCAR=17.9
Pod documented
640 0 eval q{ require Module::CoreList };
641 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
642 0 '???';
643 } else {
644 0 ▶ *core_version = sub { Module::CoreList->first_release(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
645 0 goto &core_version;
646 }
647 }
648  
649 =item C<[$file, $line, $name] = location($name)>
650  
651 Return a [file, line, name] triple for function C<$name>.
652  
653 =cut
654  
655 sub location
656 1 ▶{
Subroutine location: called CC=12 SCAR=34.8
Pod documented
657 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
658 map {
659 1 ▶ if (my ($pfx, $name) = /^([\%\$\@]?)(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = /^([\%\$\@]?)(.+)/) 1 0 1
660 1 ▶ if ($pfx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pfx) { } 0 1 1
661 0 warn "Sorry -- can't lookup variables.";
662 } else {
663 # XXX: svref_2object only seems to work with a package
664 # tacked on, but that should probably be done elsewhere...
665 1 ▶ $name = 'main::'.$name unless $name =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /::/ 0 1 1
666 0 my $cv = B::svref_2object(\&{$name});
667 1 ▶ if ($cv && defined($cv = $cv->START) && !$cv->isa('B::NULL')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cv and defined($cv = $cv->START) and not $cv->isa("B::NULL")) 1 0 1
Condition33%2/6
$cv and defined($cv = $cv->START) and not $cv->isa("B::NULL")
!ll&&!rl&&r
001
$cv and defined($cv = $cv->START)
!ll&&!rl&&r
001
MC/DC0%0/3
$cv and defined($cv = $cv->START) and not $cv->isa("B::NULL")
$cv defined($cv = $cv->START) not $cv->isa("B::NULL")
Truth table25%1/4
A and B and not(C)
A= $cvB= defined($cv = $cv->START)C= not $cv->isa("B::NULL")
ABCresult
0XX0
10X0
1100
1111
668 1 my ($file, $line) = ($cv->file, $cv->line);
669 1 ▶ if ($file !~ /^\//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file =~ m[^/]) 0 1 1
670 0 for (@INC) {
671 0 ▶ if (!ref $_ && -f "$_/$file") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ and -f "$_/$file") 0 0 0
Condition0%0/3
not ref $_ and -f "$_/$file"
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $_ and -f "$_/$file"
not ref $_ -f "$_/$file"
Truth table0%0/3
not(A) and B
A= not ref $_B= -f "$_/$file"
ABresult
0X0
100
111
672 0 $file = "$_/$file";
673 0 last;
674 }
675 }
676 }
677 1 my ($shortname) = $name =~ /^(?:.*::)([^:]+)$/;
678 1 ▶ return [Cwd::abs_path($file), $line, $shortname || $name]
Condition33%1/3
$shortname || $name
l!l&&r!l&&!r
100
MC/DC0%0/2
$shortname || $name
$shortname $name
Truth table33%1/3
A || B
A= $shortnameB= $name
ABresult
1X1
011
000
679 }
680 }
681 }
682 0 []
683 } @_;
684 }
685  
686 =item C<lexicals($subname)>
687  
688 Return a list of C<$subname>'s lexical variables. Note that this
689 includes all nested scopes -- I don't know if or how Perl
690 distinguishes inner blocks.
691  
692 =cut
693  
694 sub lexicals
695 0 ▶{
Subroutine lexicals: not called CC=3 SCAR=24.8
Pod documented
696 0 my $cv = B::svref_2object(\&{+shift});
697 0 ▶ return unless $cv && ($cv = $cv->PADLIST);
Branch: 1 branch
BranchTrueFalseTotal
unless $cv and $cv = $cv->PADLIST 0 0 0
Condition0%0/3
$cv and $cv = $cv->PADLIST
!ll&&!rl&&r
000
MC/DC0%0/2
$cv and $cv = $cv->PADLIST
$cv $cv = $cv->PADLIST
Truth table0%0/3
A and B
A= $cvB= $cv = $cv->PADLIST
ABresult
0X0
100
111
698 0 my ($names, $vals) = $cv->ARRAY;
699 map {
700 0 my $name = $_->PV; $name =~ s/\0.*$//; $name
701 } grep B::class($_) ne 'SPECIAL', $names->ARRAY;
702 }
703  
704 =item C<$lisp = tolisp($perl)>
705  
706 Convert a Perl scalar to some ELisp equivalent.
707  
708 =cut
709  
710 sub tolisp($)
711 0 ▶{
Subroutine tolisp: not called CC=9 SCAR=45.0
Pod documented
712 0 ▶ my $thing = @_ == 1 ? shift : \@_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
713 0 my $t = ref $thing;
714 0 ▶ if (!$t) {
Branch: 5 branches
BranchTrueFalseTotal
if (not $t) { } 0 0 0
elsif ($t eq 'GLOB') { } 0 0 0
elsif ($t eq 'ARRAY') { } 0 0 0
elsif ($t eq 'HASH') { } 0 0 0
elsif ($t eq 'Regexp') { } 0 0 0
715 0 ▶ if (!defined $thing) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $thing) { } 0 0 0
elsif (&looks_like_number($thing)) { } 0 0 0
716 0 'nil'
717 } elsif (looks_like_number $thing) {
718 0 ''.(0+$thing);
719 } else {
720 ## XXX Elisp and perl have slightly different
721 ## escaping conventions, so we do this crap instead.
722 0 $thing =~ s/["\\]/\\$1/g;
723 0 qq{"$thing"};
724 }
725 } elsif ($t eq 'GLOB') {
726 0 (my $name = $$thing) =~ s/\*main:://;
727 0 $name;
728 } elsif ($t eq 'ARRAY') {
729 0 '(' . join(' ', map { tolisp($_) } @$thing).')'
730 } elsif ($t eq 'HASH') {
731 '(' . join(' ', map {
732 0 '(' . tolisp($_) . " . " . tolisp($thing->{$_}) . ')'
733 } keys %$thing).')'
734 } elsif ($t eq 'Regexp') {
735 0 "'(regexp . \"" . quotemeta($thing) . '")';
736 # } elsif ($t eq 'IO') {
737 } else {
738 0 qq{"$thing"};
739 }
740 }
741  
742 =item C<printer(\@res)>
743  
744 Print C<@res> appropriately on the current filehandle. If C<$ISEVAL>
745 is true, use terse format. Otherwise, use human-readable format,
746 which can use either L<Data::Dumper>, L<YAML>, or L<Data::Dump>.
747  
748 =cut
749  
750 %PRINTER = (
751 0 ▶ dumper => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
752 0 eval q{ require Data::Dumper };
753 0 local $Data::Dumper::Deparse = 1;
754 0 local $Data::Dumper::Indent = 0;
755 0 local $_;
756 0 ▶ my $thing = @res > 1 ? \@res : $res[0];
Branch: 1 branch
BranchTrueFalseTotal
@Sepia::res > 1 ? : 0 0 0
757 0 eval {
758 0 $_ = Data::Dumper::Dumper($thing);
759 };
760 0 ▶ if (length $_ > ($ENV{COLUMNS} || 80)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ > ($ENV{"COLUMNS"} || 80)) 0 0 0
Condition0%0/2
$ENV{'COLUMNS'} || 80
l!l
00
MC/DC0%0/1
$ENV{'COLUMNS'} || 80
$ENV{'COLUMNS'}
Truth table0%0/2
A
A= $ENV{'COLUMNS'}
Aresult
11
00
761 0 $Data::Dumper::Indent = 1;
762 0 eval {
763 0 $_ = Data::Dumper::Dumper($thing);
764 };
765 }
766 0 s/\A\$VAR1 = //;
767 0 s/;\Z//;
768 0 $_;
769 },
770 0 ▶ plain => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
771 0 "@res";
772 },
773 0 ▶ dumpvar => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
774 0 ▶ if (eval q{require 'dumpvar.pl';1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require 'dumpvar.pl';1") 0 0 0
775 0 dumpvar::veryCompact(1);
776 0 ▶ $PRINTER{dumpvar} = sub { dumpValue(\@res) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
777 0 goto &{$PRINTER{dumpvar}};
778 }
779 },
780 0 ▶ yaml => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
781 0 eval q{ require YAML };
782 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
783 0 $PRINTER{dumper}->();
784 } else {
785 0 YAML::Dump(\@res);
786 }
787 },
788 0 ▶ dump => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
789 0 eval q{ require Data::Dump };
790 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
791 0 $PRINTER{dumper}->();
792 } else {
793 0 Data::Dump::dump(\@res);
794 }
795 },
796 0 ▶ peek => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
797 0 eval q{
798 require Devel::Peek;
799 require IO::Scalar;
800 };
801 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
802 0 $PRINTER{dumper}->();
803 } else {
804 0 my $ret = new IO::Scalar;
805 0 my $out = select $ret;
806 0 ▶ Devel::Peek::Dump(@res == 1 ? $res[0] : \@res);
Branch: 1 branch
BranchTrueFalseTotal
@Sepia::res == 1 ? : 0 0 0
807 0 select $out;
808 0 $ret;
809 }
810 }
811 2 );
812  
813 sub ::_()
814 0 ▶{
Subroutine _: not called CC=2 SCAR=17.9
815 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
816 @res
817 0 } else {
818 0 $_
819 }
820 }
821  
822 sub printer
823 0 ▶{
Subroutine printer: not called CC=13 SCAR=52.0
Pod documented
824 0 local *res = shift;
825 0 my $res;
826 0 @_ = @res;
827 0 ▶ $_ = @res == 1 ? $res[0] : @res == 0 ? undef : [@res];
Branch: 2 branches
BranchTrueFalseTotal
@Sepia::res == 1 ? : 0 0 0
@Sepia::res == 0 ? : 0 0 0
828 0 my $str;
829 0 ▶ if ($ISEVAL) {
Branch: 3 branches
BranchTrueFalseTotal
if ($Sepia::ISEVAL) { } 0 0 0
elsif (@Sepia::res == 1 and not $Sepia::ISEVAL and $Sepia::STRINGIFY and UNIVERSAL::can($Sepia::res[0], '()')) { } 0 0 0
elsif (not $Sepia::ISEVAL and $Sepia::COLUMNATE and @Sepia::res > 1 and not grep(ref($_), @Sepia::res)) { } 0 0 0
830 0 $res = "@res";
831 ▶ } elsif (@res == 1 && !$ISEVAL && $STRINGIFY
Condition0%0/9
@Sepia::res == 1 and not $Sepia::ISEVAL and $Sepia::STRINGIFY and UNIVERSAL::can($Sepia::res[0], "()")
!ll&&!rl&&r
000
@Sepia::res == 1 and not $Sepia::ISEVAL and $Sepia::STRINGIFY
!ll&&!rl&&r
000
@Sepia::res == 1 and not $Sepia::ISEVAL
!ll&&!rl&&r
000
MC/DC0%0/4
@Sepia::res == 1 and not $Sepia::ISEVAL and $Sepia::STRINGIFY and UNIVERSAL::can($Sepia::res[0], "()")
@Sepia::res == 1 not $Sepia::ISEVAL $Sepia::STRINGIFY UNIVERSAL::can($Sepia::res[0], "()")
Truth table0%0/5
A and not(B) and C and D
A= @Sepia::res == 1B= not $Sepia::ISEVALC= $Sepia::STRINGIFYD= UNIVERSAL::can($Sepia::res[0], "()")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
832 && UNIVERSAL::can($res[0], '()')) {
833 # overloaded?
834 0 $res = "$res[0]";
835 ▶ } elsif (!$ISEVAL && $COLUMNATE && @res > 1 && !grep ref, @res) {
Condition0%0/9
not $Sepia::ISEVAL and $Sepia::COLUMNATE and @Sepia::res > 1 and not grep(ref($_), @Sepia::res)
!ll&&!rl&&r
000
not $Sepia::ISEVAL and $Sepia::COLUMNATE and @Sepia::res > 1
!ll&&!rl&&r
000
not $Sepia::ISEVAL and $Sepia::COLUMNATE
!ll&&!rl&&r
000
MC/DC0%0/4
not $Sepia::ISEVAL and $Sepia::COLUMNATE and @Sepia::res > 1 and not grep(ref($_), @Sepia::res)
not $Sepia::ISEVAL $Sepia::COLUMNATE @Sepia::res > 1 not grep(ref($_), @Sepia::res)
Truth table0%0/5
not(A) and B and C and not(D)
A= not $Sepia::ISEVALB= $Sepia::COLUMNATEC= @Sepia::res > 1D= not grep(ref($_), @Sepia::res)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
836 0 $res = columnate(@res);
837 0 print $res;
838 0 return;
839 } else {
840 0 $res = $PRINTER{$PRINTER}->();
841 }
842 0 ▶ if ($ISEVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Sepia::ISEVAL) { } 0 0 0
843 0 print ';;;', length $res, "\n$res\n";
844 } else {
845 0 print "$res\n";
846 }
847 }
848  
849 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
850 2 $PS1 = "> ";
851 2 $PACKAGE = 'main';
852 2 $WANTARRAY = '@';
853 2 $PRINTER = 'dumper';
854 2 $COLUMNATE = 1;
855 2 $STRINGIFY = 1;
856 }
857  
858 =item C<prompt()> -- Print the REPL prompt.
859  
860 =cut
861  
862 sub prompt()
863 0 ▶{
Subroutine prompt: not called CC=1 SCAR=6.9
Pod documented
864 0 run_hook @PRE_PROMPT;
865 0 "$PACKAGE $WANTARRAY$PS1"
866 }
867  
868 sub Dump
869 0 ▶{
Subroutine Dump: not called CC=1 SCAR=6.9
Pod undocumented
870 0 eval {
871 0 Data::Dumper->Dump([$_[0]], [$_[1]]);
872 };
873 }
874  
875 =item C<$flowed = flow($width, $text)> -- Flow C<$text> to at most C<$width> columns.
876  
877 =cut
878  
879 sub flow
880 0 ▶{
Subroutine flow: not called CC=1 SCAR=6.9
Pod documented
881 0 my $n = shift;
882 0 my $n1 = int(2*$n/3);
883 0 local $_ = shift;
884 0 s/(.{$n1,$n}) /$1\n/g;
885 0 $_
886 }
887  
888 =back
889  
890 =head2 Persistence
891  
892 =over
893  
894 =item C<load \@keyvals> -- Load persisted data in C<@keyvals>.
895  
896 =item C<$ok = saveable $name> -- Return whether C<$name> is saveable.
897  
898 Saving certain magic variables leads to badness, so we avoid them.
899  
900 =item C<\@kvs = save $re> -- Return a list of name/value pairs to save.
901  
902 =back
903  
904 =cut
905  
906 sub load
907 0 ▶{
Subroutine load: not called CC=2 SCAR=10.1
Pod documented
908 0 my $a = shift;
909 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
910 0 for (@$a) {
911 0 *{$_->[0]} = $_->[1];
912 }
913 }
914  
915 2 my %BADVARS;
916 2 undef @BADVARS{qw(%INC @INC %SIG @ISA %ENV @ARGV)};
917  
918 # magic variables
919 sub saveable
920 0 ▶{
Subroutine saveable: not called CC=4 SCAR=30.0
Pod documented
921 0 local $_ = shift;
922 return !/^.[^c-zA-Z]$/ # single-letter stuff (match vars, $_, etc.)
923 && !/^.[\0-\060]/ # magic weirdness.
924 && !/^._</ # debugger info
925 0 ▶ && !exists $BADVARS{$_}; # others.
Condition0%0/9
/^.[^c-zA-Z]$/ || /^.[\0-\060]/ || /^._</ || exists $BADVARS{$_}
l!l&&r!l&&!r
000
/^.[^c-zA-Z]$/ or /^.[\0-\060]/ or /^._</
l!l&&r!l&&!r
000
/^.[^c-zA-Z]$/ or /^.[\0-\060]/
l!l&&r!l&&!r
000
MC/DC0%0/4
/^.[^c-zA-Z]$/ || /^.[\0-\060]/ || /^._</ || exists $BADVARS{$_}
/^.[^c-zA-Z]$/ /^.[\0-\060]/ /^._</ exists $BADVARS{$_}
Truth table0%0/5
A or B or C || D
A= /^.[^c-zA-Z]$/B= /^.[\0-\060]/C= /^._</D= exists $BADVARS{$_}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
926 }
927  
928 sub save
929 0 ▶{
Subroutine save: not called CC=2 SCAR=16.6
Pod documented
930 0 my ($re) = @_;
931 0 my @save;
932 0 $re = qr/(?:^|::)$re/;
933 2 ▶ no strict; # no kidding...
Subroutine BEGIN: called CC=1 SCAR=0.0
934 0 ▶ my_walksymtable {
Subroutine __ANON__: not called CC=10 SCAR=47.0
935 0 ▶ return if /::$/
Branch: 1 branch
BranchTrueFalseTotal
if /::$/ or $stash =~ /^(?:::)?(?:warnings|Config|strict|B)\b/ 0 0 0
Condition0%0/3
/::$/ or $stash =~ /^(?:::)?(?:warnings|Config|strict|B)\b/
l!l&&r!l&&!r
000
MC/DC0%0/2
/::$/ or $stash =~ /^(?:::)?(?:warnings|Config|strict|B)\b/
/::$/ $stash =~ /^(?:::)?(?:warnings|Config|strict|B)\b/
Truth table0%0/3
A or B
A= /::$/B= $stash =~ /^(?:::)?(?:warnings|Config|strict|B)\b/
ABresult
1X1
011
000
936 || $stash =~ /^(?:::)?(?:warnings|Config|strict|B)\b/;
937 0 ▶ if (/$re/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/$re/) 0 0 0
938 0 my $name = "$stash$_";
939 0 ▶ if (defined ${$name} and saveable '$'.$_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${$name;} and saveable('$' . $_)) 0 0 0
Condition0%0/3
defined ${$name;} and saveable('$' . $_)
!ll&&!rl&&r
000
MC/DC0%0/2
defined ${$name;} and saveable('$' . $_)
defined ${$name;} saveable('$' . $_)
Truth table0%0/3
A and B
A= defined ${$name;}B= saveable('$' . $_)
ABresult
0X0
100
111
940 0 push @save, [$name, \$$name];
941 }
942 0 ▶ if (defined *{$name}{HASH} and saveable '%'.$_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{$name;}{"HASH"} and saveable('%' . $_)) 0 0 0
Condition0%0/3
defined *{$name;}{"HASH"} and saveable('%' . $_)
!ll&&!rl&&r
000
MC/DC0%0/2
defined *{$name;}{"HASH"} and saveable('%' . $_)
defined *{$name;}{"HASH"} saveable('%' . $_)
Truth table0%0/3
A and B
A= defined *{$name;}{"HASH"}B= saveable('%' . $_)
ABresult
0X0
100
111
943 0 push @save, [$name, \%{$name}];
944 }
945 0 ▶ if (defined *{$name}{ARRAY} and saveable '@'.$_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{$name;}{"ARRAY"} and saveable('@' . $_)) 0 0 0
Condition0%0/3
defined *{$name;}{"ARRAY"} and saveable('@' . $_)
!ll&&!rl&&r
000
MC/DC0%0/2
defined *{$name;}{"ARRAY"} and saveable('@' . $_)
defined *{$name;}{"ARRAY"} saveable('@' . $_)
Truth table0%0/3
A and B
A= defined *{$name;}{"ARRAY"}B= saveable('@' . $_)
ABresult
0X0
100
111
946 0 push @save, [$name, \@{$name}];
947 }
948 }
949 0 } '::';
950 0 print STDERR "$_->[0] " for @save;
951 0 print STDERR "\n";
952 0 \@save;
953 }
954  
955 =head2 REPL shortcuts
956  
957 The function implementing built-in REPL shortcut ",X" is named C<repl_X>.
958  
959 =over
960  
961 =item C<define_shortcut $name, $sub [, $doc [, $shortdoc]]>
962  
963 Define $name as a shortcut for function $sub.
964  
965 =cut
966  
967 sub define_shortcut
968 0 ▶{
Subroutine define_shortcut: not called CC=3 SCAR=24.8
Pod documented
969 0 my ($name, $doc, $short, $fn);
970 0 ▶ if (@_ == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 2) { } 0 0 0
elsif (@_ == 3) { } 0 0 0
971 0 ($name, $fn) = @_;
972 0 $short = $name;
973 0 $doc = '';
974 } elsif (@_ == 3) {
975 0 ($name, $fn, $doc) = @_;
976 0 $short = $name;
977 } else {
978 0 ($name, $fn, $short, $doc) = @_;
979 }
980 0 $REPL{$name} = $fn;
981 0 $REPL_DOC{$name} = $doc;
982 0 $REPL_SHORT{$name} = $short;
983 0 abbrev \%RK, keys %REPL;
984 }
985  
986 =item C<alias_shortcut $new, $old>
987  
988 Alias $new to do the same as $old.
989  
990 =cut
991  
992 sub alias_shortcut
993 0 ▶{
Subroutine alias_shortcut: not called CC=1 SCAR=6.9
Pod documented
994 0 my ($new, $old) = @_;
995 0 $REPL{$new} = $REPL{$old};
996 0 $REPL_DOC{$new} = $REPL_DOC{$old};
997 0 ($REPL_SHORT{$new} = $REPL_SHORT{$old}) =~ s/^\Q$old\E/$new/;
998 0 abbrev %RK, keys %REPL;
999 }
1000  
1001 =item C<define_shortcuts()>
1002  
1003 Define the default REPL shortcuts.
1004  
1005 =cut
1006  
1007 sub define_shortcuts
1008 0 ▶{
Subroutine define_shortcuts: not called CC=1 SCAR=6.9
Pod documented
1009 0 define_shortcut 'help', \&Sepia::repl_help,
1010 'help [CMD]',
1011 'Display help on all commands, or just CMD.';
1012 0 define_shortcut 'cd', \&Sepia::repl_chdir,
1013 'cd DIR', 'Change directory to DIR';
1014 0 define_shortcut 'pwd', \&Sepia::repl_pwd,
1015 'Show current working directory';
1016 0 define_shortcut 'methods', \&Sepia::repl_methods,
1017 'methods X [RE]',
1018 'List methods for reference or package X, matching optional pattern RE';
1019 0 define_shortcut 'package', \&Sepia::repl_package,
1020 'package PKG', 'Set evaluation package to PKG';
1021 0 define_shortcut 'who', \&Sepia::repl_who,
1022 'who PKG [RE]',
1023 'List variables and subs in PKG matching optional pattern RE.';
1024 0 define_shortcut 'wantarray', \&Sepia::repl_wantarray,
1025 'wantarray [0|1]', 'Set or toggle evaluation context';
1026 0 define_shortcut 'format', \&Sepia::repl_format,
1027 'format [TYPE]', "Set output formatter to TYPE (one of 'dumper', 'dump', 'yaml', 'plain'; default: 'dumper'), or show current type.";
1028 0 define_shortcut 'strict', \&Sepia::repl_strict,
1029 'strict [0|1]', 'Turn \'use strict\' mode on or off';
1030 0 define_shortcut 'quit', \&Sepia::repl_quit,
1031 'Quit the REPL';
1032 0 alias_shortcut 'exit', 'quit';
1033 0 define_shortcut 'restart', \&Sepia::repl_restart,
1034 'Reload Sepia.pm and relaunch the REPL.';
1035 0 define_shortcut 'shell', \&Sepia::repl_shell,
1036 'shell CMD ...', 'Run CMD in the shell';
1037 0 define_shortcut 'eval', \&Sepia::repl_eval,
1038 'eval EXP', '(internal)';
1039 0 define_shortcut 'size', \&Sepia::repl_size,
1040 'size PKG [RE]',
1041 'List total sizes of objects in PKG matching optional pattern RE.';
1042 0 define_shortcut define => \&Sepia::repl_define,
1043 'define NAME [\'DOC\'] BODY',
1044 'Define NAME as a shortcut executing BODY';
1045 0 define_shortcut undef => \&Sepia::repl_undef,
1046 'undef NAME', 'Undefine shortcut NAME';
1047 0 define_shortcut test => \&Sepia::repl_test,
1048 'test FILE...', 'Run tests interactively.';
1049 0 define_shortcut load => \&Sepia::repl_load,
1050 'load [FILE]', 'Load state from FILE.';
1051 0 define_shortcut save => \&Sepia::repl_save,
1052 'save [PATTERN [FILE]]', 'Save variables matching PATTERN to FILE.';
1053 0 define_shortcut reload => \&Sepia::repl_reload,
1054 'reload [MODULE | /RE/]', 'Reload MODULE, or all modules matching RE.';
1055 0 define_shortcut freload => \&Sepia::repl_full_reload,
1056 'freload MODULE', 'Reload MODULE and all its dependencies.';
1057 0 define_shortcut time => \&Sepia::repl_time,
1058 'time [0|1]', 'Print timing information for each command.';
1059 0 define_shortcut lsmod => \&Sepia::repl_lsmod,
1060 'lsmod [PATTERN]', 'List loaded modules matching PATTERN.';
1061 }
1062  
1063 =item C<repl_strict([$value])>
1064  
1065 Toggle strict mode. Requires L<PadWalker> and L<Devel::LexAlias>.
1066  
1067 =cut
1068  
1069 sub repl_strict
1070 0 ▶{
Subroutine repl_strict: not called CC=2 SCAR=17.9
Pod documented
1071 0 eval q{ use PadWalker qw(peek_sub set_closed_over);
1072 use Devel::LexAlias 'lexalias';
1073 };
1074 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
1075 0 print "Strict mode requires PadWalker and Devel::LexAlias.\n";
1076 } else {
1077 0 ▶ *repl_strict = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1078 0 my $x = as_boolean(shift, $STRICT);
1079 0 ▶ if ($x && !$STRICT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x and not $Sepia::STRICT) { } 0 0 0
elsif (not $x) { } 0 0 0
Condition0%0/3
$x and not $Sepia::STRICT
!ll&&!rl&&r
000
MC/DC0%0/2
$x and not $Sepia::STRICT
$x not $Sepia::STRICT
Truth table0%0/3
A and not(B)
A= $xB= not $Sepia::STRICT
ABresult
0X0
100
111
1080 0 $STRICT = {};
1081 } elsif (!$x) {
1082 0 undef $STRICT;
1083 }
1084 0 };
1085 0 goto &repl_strict;
1086 }
1087 }
1088  
1089 sub repl_size
1090 0 ▶{
Subroutine repl_size: not called CC=2 SCAR=16.8
Pod undocumented
1091 0 eval q{ require Devel::Size };
1092 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
1093 0 print "Size requires Devel::Size.\n";
1094 } else {
1095 0 ▶ *Sepia::repl_size = sub {
Subroutine __ANON__: not called CC=13 SCAR=50.3
1096 0 my ($pkg, $re) = split ' ', shift, 2;
1097 0 ▶ if ($re) {
Branch: 3 branches
BranchTrueFalseTotal
if ($re) { } 0 0 0
elsif (not $re and $pkg =~ m[^/(.*?)/?$]) { } 0 0 0
elsif (not $pkg) { } 0 0 0
1098 0 $re =~ s!^/|/$!!g;
1099 ▶ } elsif (!$re && $pkg =~ /^\/(.*?)\/?$/) {
Condition0%0/3
not $re and $pkg =~ m[^/(.*?)/?$]
!ll&&!rl&&r
000
MC/DC0%0/2
not $re and $pkg =~ m[^/(.*?)/?$]
not $re $pkg =~ m[^/(.*?)/?$]
Truth table0%0/3
not(A) and B
A= not $reB= $pkg =~ m[^/(.*?)/?$]
ABresult
0X0
100
111
1100 0 $re = $1;
1101 0 undef $pkg;
1102 } elsif (!$pkg) {
1103 0 $re = '.';
1104 }
1105 0 my (@who, %res);
1106 0 ▶ if ($STRICT && !$pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Sepia::STRICT and not $pkg) { } 0 0 0
Condition0%0/3
$Sepia::STRICT and not $pkg
!ll&&!rl&&r
000
MC/DC0%0/2
$Sepia::STRICT and not $pkg
$Sepia::STRICT not $pkg
Truth table0%0/3
A and not(B)
A= $Sepia::STRICTB= not $pkg
ABresult
0X0
100
111
1107 0 @who = grep /$re/, keys %$STRICT;
1108 0 for (@who) {
1109 0 $res{$_} = Devel::Size::total_size($Sepia::STRICT->{$_});
1110 }
1111 } else {
1112 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1113 0 ▶ $pkg ||= 'main';
Condition0%0/2
$pkg ||= "main"
l!l
00
MC/DC0%0/1
$pkg ||= "main"
$pkg
Truth table0%0/2
A
A= $pkg
Aresult
11
00
1114 0 @who = who($pkg, $re);
1115 0 for (@who) {
1116 0 ▶ next unless /^[\$\@\%\&]/; # skip subs.
Branch: 1 branch
BranchTrueFalseTotal
unless /^[\$\@\%\&]/ 0 0 0
1117 0 ▶ next if $_ eq '%SIG';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "%SIG" 0 0 0
1118 0 $res{$_} = eval "no strict; package $pkg; Devel::Size::total_size \\$_;";
1119 }
1120 }
1121 0 my $len = max(3, map { length } @who) + 4;
1122 0 my $fmt = '%-'.$len."s%10d\n";
1123 # print "$pkg\::/$re/\n";
1124 0 print 'Var', ' ' x ($len + 2), "Bytes\n";
1125 0 print '-' x ($len-4), ' ' x 9, '-' x 5, "\n";
1126 0 for (sort { $res{$b} <=> $res{$a} } keys %res) {
1127 0 printf $fmt, $_, $res{$_};
1128 }
1129 0 };
1130 0 goto &repl_size;
1131 }
1132 }
1133  
1134 =item C<repl_time([$value])>
1135  
1136 Toggle command timing.
1137  
1138 =cut
1139  
1140 2 my ($time_res, $TIME);
1141 sub time_pre_prompt_bsd
1142 0 ▶{
Subroutine time_pre_prompt_bsd: not called CC=2 SCAR=17.9
Pod undocumented
1143 0 ▶ printf "(%.2gr, %.2gu, %.2gs) ", @{$time_res} if defined $time_res;
Branch: 1 branch
BranchTrueFalseTotal
if defined $time_res 0 0 0
1144 };
1145  
1146 sub time_pre_prompt_plain
1147 0 ▶{
Subroutine time_pre_prompt_plain: not called CC=2 SCAR=17.9
Pod undocumented
1148 0 ▶ printf "(%.2gs) ", $time_res if defined $time_res;
Branch: 1 branch
BranchTrueFalseTotal
if defined $time_res 0 0 0
1149 }
1150  
1151 sub repl_time
1152 0 ▶{
Subroutine repl_time: not called CC=4 SCAR=30.0
Pod documented
1153 0 $TIME = as_boolean(shift, $TIME);
1154 0 ▶ if (!$TIME) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($TIME) 0 0 0
1155 0 print STDERR "Removing time hook.\n";
1156 0 remove_hook @PRE_PROMPT, 'Sepia::time_pre_prompt';
1157 0 remove_hook @PRE_EVAL, 'Sepia::time_pre_eval';
1158 0 remove_hook @POST_EVAL, 'Sepia::time_post_eval';
1159 0 return;
1160 }
1161 0 print STDERR "Adding time hook.\n";
1162 0 add_hook @PRE_PROMPT, 'Sepia::time_pre_prompt';
1163 0 add_hook @PRE_EVAL, 'Sepia::time_pre_eval';
1164 0 add_hook @POST_EVAL, 'Sepia::time_post_eval';
1165 0 my $has_bsd = eval q{ use BSD::Resource 'getrusage';1 };
1166 0 my $has_hires = eval q{ use Time::HiRes qw(gettimeofday tv_interval);1 };
1167 0 my ($t0);
1168 0 ▶ if ($has_bsd) { # sweet! getrusage!
Branch: 2 branches
BranchTrueFalseTotal
if ($has_bsd) { } 0 0 0
elsif ($has_hires) { } 0 0 0
1169 0 my ($user, $sys, $real);
1170 0 ▶ *time_pre_eval = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1171 0 undef $time_res;
1172 0 ($user, $sys) = getrusage();
1173 0 ▶ $real = $has_hires ? [gettimeofday()] : $user+$sys;
Branch: 1 branch
BranchTrueFalseTotal
$has_hires ? : 0 0 0
1174 0 };
1175 0 ▶ *time_post_eval = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1176 0 my ($u2, $s2) = getrusage();
1177 0 ▶ $time_res = [$has_hires ? tv_interval($real, [gettimeofday()])
Branch: 1 branch
BranchTrueFalseTotal
$has_hires ? : 0 0 0
1178 : $s2 + $u2 - $real,
1179 ($u2 - $user), ($s2 - $sys)];
1180 0 };
1181 0 *time_pre_prompt = *time_pre_prompt_bsd;
1182 } elsif ($has_hires) { # at least we have msec...
1183 0 ▶ *time_pre_eval = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1184 0 undef $time_res;
1185 0 $t0 = [gettimeofday()];
1186 0 };
1187 0 ▶ *time_post_eval = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1188 0 $time_res = tv_interval($t0, [gettimeofday()]);
1189 0 };
1190 0 *time_pre_prompt = *time_pre_prompt_plain;
1191 } else {
1192 0 ▶ *time_pre_eval = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1193 0 undef $time_res;
1194 0 $t0 = time;
1195 0 };
1196 0 ▶ *time_post_eval = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1197 0 $time_res = (time - $t0);
1198 0 };
1199 0 *time_pre_prompt = *time_pre_prompt_plain;
1200 }
1201 }
1202  
1203 sub repl_help
1204 0 ▶{
Subroutine repl_help: not called CC=5 SCAR=34.0
Pod undocumented
1205 0 ▶ my $width = $ENV{COLUMNS} || 80;
Condition0%0/2
$ENV{'COLUMNS'} || 80
l!l
00
MC/DC0%0/1
$ENV{'COLUMNS'} || 80
$ENV{'COLUMNS'}
Truth table0%0/2
A
A= $ENV{'COLUMNS'}
Aresult
11
00
1206 0 my $args = shift;
1207 0 ▶ if ($args =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args =~ /\S/) { } 0 0 0
1208 0 $args =~ s/^\s+//;
1209 0 $args =~ s/\s+$//;
1210 0 my $full = $RK{$args};
1211 0 ▶ if ($full) {
Branch: 1 branch
BranchTrueFalseTotal
if ($full) { } 0 0 0
1212 0 my $short = $REPL_SHORT{$full};
1213 0 my $flow = flow($width - length $short - 4, $REPL_DOC{$full});
1214 0 $flow =~ s/(.)\n/"$1\n".(' 'x (4 + length $short))/eg;
1215 0 print "$short $flow\n";
1216 } else {
1217 0 print "$args: no such command\n";
1218 }
1219 } else {
1220 0 my $left = 1 + max map length, values %REPL_SHORT;
1221 0 print "REPL commands (prefixed with ','):\n";
1222  
1223 0 for (sort keys %REPL) {
1224 0 my $flow = flow($width - $left, $REPL_DOC{$_});
1225 0 $flow =~ s/(.)\n/"$1\n".(' ' x $left)/eg;
1226 0 printf "%-${left}s%s\n", $REPL_SHORT{$_}, $flow;
1227 }
1228 }
1229 }
1230  
1231 sub repl_define
1232 0 ▶{
Subroutine repl_define: not called CC=4 SCAR=30.0
Pod undocumented
1233 0 local $_ = shift;
1234 0 my ($name, $doc, $body);
1235 0 ▶ if (/^\s*(\S+)\s+'((?:[^'\\]|\\.)*)'\s+(.+)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^\s*(\S+)\s+'((?:[^'\\]|\\.)*)'\s+(.+)/) { } 0 0 0
elsif (/^\s*(\S+)\s+(\S.*)/) { } 0 0 0
1236 0 ($name, $doc, $body) = ($1, $2, $3);
1237 } elsif (/^\s*(\S+)\s+(\S.*)/) {
1238 0 ($name, $doc, $body) = ($1, $2, $2);
1239 } else {
1240 0 print "usage: define NAME ['doc'] BODY...\n";
1241 0 return;
1242 }
1243 0 my $sub = eval "sub { do { $body } }";
1244 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1245 0 print "usage: define NAME ['doc'] BODY...\n\t$@\n";
1246 0 return;
1247 }
1248 0 define_shortcut $name, $sub, $doc;
1249 # %RK = abbrev keys %REPL;
1250 }
1251  
1252 sub repl_undef
1253 0 ▶{
Subroutine repl_undef: not called CC=2 SCAR=17.9
Pod undocumented
1254 0 my $name = shift;
1255 0 $name =~ s/^\s*//;
1256 0 $name =~ s/\s*$//;
1257 0 my $full = $RK{$name};
1258 0 ▶ if ($full) {
Branch: 1 branch
BranchTrueFalseTotal
if ($full) { } 0 0 0
1259 0 delete $REPL{$full};
1260 0 delete $REPL_SHORT{$full};
1261 0 delete $REPL_DOC{$full};
1262 0 abbrev \%RK, keys %REPL;
1263 } else {
1264 0 print "$name: no such shortcut.\n";
1265 }
1266 }
1267  
1268 sub repl_format
1269 0 ▶{
Subroutine repl_format: not called CC=4 SCAR=30.0
Pod undocumented
1270 0 my $t = shift;
1271 0 chomp $t;
1272 0 ▶ if ($t eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq '') { } 0 0 0
1273 0 ▶ print "printer = $PRINTER, columnate = @{[$COLUMNATE ? 1 : 0]}\n";
Branch: 1 branch
BranchTrueFalseTotal
$Sepia::COLUMNATE ? : 0 0 0
1274 } else {
1275 0 my %formats = abbrev keys %PRINTER;
1276 0 ▶ if (exists $formats{$t}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $formats{$t}) { } 0 0 0
1277 0 $PRINTER = $formats{$t};
1278 } else {
1279 0 warn "No such format '$t' (dumper, dump, yaml, plain).\n";
1280 }
1281 }
1282 }
1283  
1284 sub repl_chdir
1285 0 ▶{
Subroutine repl_chdir: not called CC=2 SCAR=17.9
Pod undocumented
1286 0 chomp(my $dir = shift);
1287 0 $dir =~ s/^~\//$ENV{HOME}\//;
1288 0 $dir =~ s/\$HOME/$ENV{HOME}/;
1289 0 ▶ if (-d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir) { } 0 0 0
1290 0 chdir $dir;
1291 0 my $ecmd = '(cd "'.Cwd::getcwd().'")';
1292 0 print ";;;###".length($ecmd)."\n$ecmd\n";
1293 } else {
1294 0 warn "Can't chdir\n";
1295 }
1296 }
1297  
1298 sub repl_pwd
1299 0 ▶{
Subroutine repl_pwd: not called CC=1 SCAR=6.9
Pod undocumented
1300 0 print Cwd::getcwd(), "\n";
1301 }
1302  
1303 =item C<who($package [, $re])>
1304  
1305 List variables and functions in C<$package> matching C<$re>, or all
1306 variables if C<$re> is absent.
1307  
1308 =cut
1309  
1310 sub who
1311 0 ▶{
Subroutine who: not called CC=15 SCAR=53.2
Pod documented
1312 0 my ($pack, $re_str) = @_;
1313 0 ▶ $re_str ||= '.?';
Condition0%0/2
$re_str ||= ".?"
l!l
00
MC/DC0%0/1
$re_str ||= ".?"
$re_str
Truth table0%0/2
A
A= $re_str
Aresult
11
00
1314 0 my $re = qr/$re_str/;
1315 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1316 0 ▶ if ($re_str =~ /^[\$\@\%\&]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_str =~ /^[\$\@\%\&]/) { } 0 0 0
1317 ## sigil given -- match it
1318 sort grep /$re/, map {
1319 0 my $name = $pack.'::'.$_;
1320 0 ▶ (defined *{$name}{HASH} ? '%'.$_ : (),
Branch: 1 branch
BranchTrueFalseTotal
defined *{$name;}{'ARRAY'} ? : 0 0 0
1321 0 ▶ defined *{$name}{ARRAY} ? '@'.$_ : (),
Branch: 1 branch
BranchTrueFalseTotal
defined *{$name;}{'CODE'} ? : 0 0 0
1322 0 ▶ defined *{$name}{CODE} ? $_ : (),
Branch: 1 branch
BranchTrueFalseTotal
defined ${$name;} ? : 0 0 0
1323 0 ▶ defined ${$name} ? '$'.$_ : (), # ?
Branch: 1 branch
BranchTrueFalseTotal
defined *{$name;}{'HASH'} ? : 0 0 0
Condition0%0/6
!(/::$/ || /^(?:_<|[^\w])/) && /$re/
!ll&&!rl&&r
000
/::$/ || /^(?:_<|[^\w])/
l!l&&r!l&&!r
000
MC/DC0%0/3
!(/::$/ || /^(?:_<|[^\w])/) && /$re/
/::$/ /^(?:_<|[^\w])/ /$re/
Truth table0%0/4
not(A || B) && C
A= /::$/B= /^(?:_<|[^\w])/C= /$re/
ABCresult
1XX0
01X0
0000
0011
1324 )
1325 0 } grep !/::$/ && !/^(?:_<|[^\w])/ && /$re/, keys %{$pack.'::'};
1326 } else {
1327 ## no sigil -- don't match it
1328 sort map {
1329 0 my $name = $pack.'::'.$_;
1330 0 ▶ (defined *{$name}{HASH} ? '%'.$_ : (),
Branch: 1 branch
BranchTrueFalseTotal
defined *{$name;}{'ARRAY'} ? : 0 0 0
1331 0 ▶ defined *{$name}{ARRAY} ? '@'.$_ : (),
Branch: 1 branch
BranchTrueFalseTotal
defined *{$name;}{'CODE'} ? : 0 0 0
1332 0 ▶ defined *{$name}{CODE} ? $_ : (),
Branch: 1 branch
BranchTrueFalseTotal
defined ${$name;} ? : 0 0 0
1333 0 ▶ defined ${$name} ? '$'.$_ : (), # ?
Branch: 1 branch
BranchTrueFalseTotal
defined *{$name;}{'HASH'} ? : 0 0 0
Condition0%0/6
!(/::$/ || /^(?:_<|[^\w])/) && /$re/
!ll&&!rl&&r
000
/::$/ || /^(?:_<|[^\w])/
l!l&&r!l&&!r
000
MC/DC0%0/3
!(/::$/ || /^(?:_<|[^\w])/) && /$re/
/::$/ /^(?:_<|[^\w])/ /$re/
Truth table0%0/4
not(A || B) && C
A= /::$/B= /^(?:_<|[^\w])/C= /$re/
ABCresult
1XX0
01X0
0000
0011
1334 )
1335 0 } grep !/::$/ && !/^(?:_<|[^\w])/ && /$re/, keys %{$pack.'::'};
1336 }
1337 }
1338  
1339 =item C<$text = columnate(@items)>
1340  
1341 Format C<@items> in columns such that they fit within C<$ENV{COLUMNS}>
1342 columns.
1343  
1344 =cut
1345  
1346 sub columnate
1347 0 ▶{
Subroutine columnate: not called CC=8 SCAR=42.8
Pod documented
1348 0 my $len = 0;
1349 0 ▶ my $width = $ENV{COLUMNS} || 80;
Condition0%0/2
$ENV{'COLUMNS'} || 80
l!l
00
MC/DC0%0/1
$ENV{'COLUMNS'} || 80
$ENV{'COLUMNS'}
Truth table0%0/2
A
A= $ENV{'COLUMNS'}
Aresult
11
00
1350 0 for (@_) {
1351 0 ▶ $len = length if $len < length;
Branch: 1 branch
BranchTrueFalseTotal
if $len < length $_ 0 0 0
1352 }
1353 0 ▶ my $nc = int($width / ($len+1)) || 1;
Condition0%0/2
int $width / ($len + 1) || 1
l!l
00
MC/DC0%0/1
int $width / ($len + 1) || 1
int $width / ($len + 1)
Truth table0%0/2
A
A= int $width / ($len + 1)
Aresult
11
00
1354 0 ▶ my $nr = int(@_ / $nc) + (@_ % $nc ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
@_ % $nc ? : 0 0 0
1355 0 my $fmt = ('%-'.($len+1).'s') x ($nc-1) . "%s\n";
1356 0 my @incs = map { $_ * $nr } 0..$nc-1;
1357 0 my $str = '';
1358 0 for my $r (0..$nr-1) {
1359 0 ▶ $str .= sprintf $fmt, map { defined($_) ? $_ : '' }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
1360 0 @_[map { $r + $_ } @incs];
1361 }
1362 0 $str =~ s/ +$//m;
1363 0 $str
1364 }
1365  
1366 sub repl_who
1367 0 ▶{
Subroutine repl_who: not called CC=9 SCAR=45.0
Pod undocumented
1368 0 my ($pkg, $re) = split ' ', shift, 2;
1369 0 ▶ if ($re) {
Branch: 3 branches
BranchTrueFalseTotal
if ($re) { } 0 0 0
elsif (not $re and $pkg =~ m[^/(.*?)/?$]) { } 0 0 0
elsif (not $pkg) { } 0 0 0
1370 0 $re =~ s!^/|/$!!g;
1371 ▶ } elsif (!$re && $pkg =~ /^\/(.*?)\/?$/) {
Condition0%0/3
not $re and $pkg =~ m[^/(.*?)/?$]
!ll&&!rl&&r
000
MC/DC0%0/2
not $re and $pkg =~ m[^/(.*?)/?$]
not $re $pkg =~ m[^/(.*?)/?$]
Truth table0%0/3
not(A) and B
A= not $reB= $pkg =~ m[^/(.*?)/?$]
ABresult
0X0
100
111
1372 0 $re = $1;
1373 0 undef $pkg;
1374 } elsif (!$pkg) {
1375 0 $re = '.';
1376 }
1377 0 my @x;
1378 0 ▶ if ($STRICT && !$pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Sepia::STRICT and not $pkg) { } 0 0 0
Condition0%0/3
$Sepia::STRICT and not $pkg
!ll&&!rl&&r
000
MC/DC0%0/2
$Sepia::STRICT and not $pkg
$Sepia::STRICT not $pkg
Truth table0%0/3
A and not(B)
A= $Sepia::STRICTB= not $pkg
ABresult
0X0
100
111
1379 0 @x = grep /$re/, keys %$STRICT;
1380 0 $pkg = '(lexical)';
1381 } else {
1382 0 ▶ $pkg ||= $PACKAGE;
Condition0%0/3
$pkg ||= $Sepia::PACKAGE
l!l&&r!l&&!r
000
MC/DC0%0/2
$pkg ||= $Sepia::PACKAGE
$pkg $Sepia::PACKAGE
Truth table0%0/3
A ||= B
A= $pkgB= $Sepia::PACKAGE
ABresult
1X1
011
000
1383 0 @x = who($pkg, $re);
1384 }
1385 0 ▶ print($pkg, "::/$re/\n", columnate @x) if @x;
Branch: 1 branch
BranchTrueFalseTotal
if @x 0 0 0
1386 }
1387  
1388 =item C<@m = methods($package [, $qualified])>
1389  
1390 List method names in C<$package> and its parents. If C<$qualified>,
1391 return full "CLASS::NAME" rather than just "NAME."
1392  
1393 =cut
1394  
1395 sub methods
1396 0 ▶{
Subroutine methods: not called CC=4 SCAR=27.1
Pod documented
1397 0 my ($pack, $qualified) = @_;
1398 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1399 my @own = $qualified ? grep {
1400 0 defined *{$_}{CODE}
1401 0 } map { "$pack\::$_" } keys %{$pack.'::'}
1402 : grep {
1403 0 defined &{"$pack\::$_"}
1404 0 ▶ } keys %{$pack.'::'};
Branch: 1 branch
BranchTrueFalseTotal
$qualified ? : 0 0 0
1405 0 ▶ if (exists ${$pack.'::'}{ISA} && *{$pack.'::ISA'}{ARRAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $pack . '::' }->{"ISA"} and *{$pack . '::ISA';}{"ARRAY"}) 0 0 0
Condition0%0/2
exists do { $pack . '::' }->{"ISA"} and *{$pack . '::ISA';}{"ARRAY"}
!ll
00
MC/DC0%0/1
exists do { $pack . '::' }->{"ISA"} and *{$pack . '::ISA';}{"ARRAY"}
exists do { $pack . '::' }->{"ISA"}
Truth table0%0/2
A
A= exists do { $pack . '::' }->{"ISA"}
Aresult
00
11
1406 0 my %m;
1407 0 undef @m{@own, map methods($_, $qualified), @{$pack.'::ISA'}};
1408 0 @own = keys %m;
1409 }
1410 0 @own;
1411 }
1412  
1413 sub repl_methods
1414 0 ▶{
Subroutine repl_methods: not called CC=4 SCAR=30.0
Pod undocumented
1415 0 my ($x, $re) = split ' ', shift;
1416 0 $x =~ s/^\s+//;
1417 0 $x =~ s/\s+$//;
1418 0 ▶ if ($x =~ /^\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /^\$/) 0 0 0
1419 0 $x = $REPL{eval}->("ref $x");
1420 0 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1421 }
1422 0 ▶ $re ||= '.?';
Condition0%0/2
$re ||= ".?"
l!l
00
MC/DC0%0/1
$re ||= ".?"
$re
Truth table0%0/2
A
A= $re
Aresult
11
00
1423 0 $re = qr/$re/;
1424 0 print columnate sort { $a cmp $b } grep /$re/, methods $x;
1425 }
1426  
1427 sub as_boolean
1428 0 ▶{
Subroutine as_boolean: not called CC=2 SCAR=17.9
Pod undocumented
1429 0 my ($val, $cur) = @_;
1430 0 $val =~ s/\s+//g;
1431 0 ▶ length($val) ? $val : !$cur;
Branch: 1 branch
BranchTrueFalseTotal
length $val ? : 0 0 0
1432 }
1433  
1434 sub repl_wantarray
1435 0 ▶{
Subroutine repl_wantarray: not called CC=4 SCAR=30.0
Pod undocumented
1436 0 ▶ $WANTARRAY = shift || $WANTARRAY;
Condition0%0/3
shift() || $Sepia::WANTARRAY
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $Sepia::WANTARRAY
shift() $Sepia::WANTARRAY
Truth table0%0/3
A || B
A= shift()B= $Sepia::WANTARRAY
ABresult
1X1
011
000
1437 0 ▶ $WANTARRAY = '' unless $WANTARRAY eq '@' || $WANTARRAY eq '$';
Branch: 1 branch
BranchTrueFalseTotal
unless $Sepia::WANTARRAY eq "\@" or $Sepia::WANTARRAY eq "\$" 0 0 0
Condition0%0/3
$Sepia::WANTARRAY eq "\@" or $Sepia::WANTARRAY eq "\$"
l!l&&r!l&&!r
000
MC/DC0%0/2
$Sepia::WANTARRAY eq "\@" or $Sepia::WANTARRAY eq "\$"
$Sepia::WANTARRAY eq "\@" $Sepia::WANTARRAY eq "\$"
Truth table0%0/3
A or B
A= $Sepia::WANTARRAY eq "\@"B= $Sepia::WANTARRAY eq "\$"
ABresult
1X1
011
000
1438 }
1439  
1440 sub repl_package
1441 0 ▶{
Subroutine repl_package: not called CC=1 SCAR=6.9
Pod undocumented
1442 0 chomp(my $p = shift);
1443 0 $PACKAGE = $p;
1444 }
1445  
1446 sub repl_quit
1447 0 ▶{
Subroutine repl_quit: not called CC=1 SCAR=6.9
Pod undocumented
1448 0 $REPL_QUIT = 1;
1449 0 last repl;
1450 }
1451  
1452 sub repl_restart
1453 0 ▶{
Subroutine repl_restart: not called CC=2 SCAR=17.9
Pod undocumented
1454 0 do $INC{'Sepia.pm'};
1455 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
1456 0 print "Restart failed:\n$@\n";
1457 } else {
1458 0 $REPL_LEVEL = 0; # ok?
1459 0 goto &Sepia::repl;
1460 }
1461 }
1462  
1463 sub repl_shell
1464 0 ▶{
Subroutine repl_shell: not called CC=1 SCAR=6.9
Pod undocumented
1465 0 my $cmd = shift;
1466 0 print `$cmd 2>& 1`;
1467 }
1468  
1469 # Stolen from Lexical::Persistence, then simplified.
1470 sub call_strict
1471 0 ▶{
Subroutine call_strict: not called CC=7 SCAR=40.3
Pod undocumented
1472 0 my ($sub) = @_;
1473  
1474 # steal any new "my" variables
1475 0 my $pad = peek_sub($sub);
1476 0 for my $k (keys %$pad) {
1477 0 ▶ unless (exists $STRICT->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Sepia::STRICT->{$k}) 0 0 0
1478 0 ▶ if ($k =~ /^\$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($k =~ /^\$/) { } 0 0 0
elsif ($k =~ /^\@/) { } 0 0 0
elsif ($k =~ /^\%/) { } 0 0 0
1479 0 $STRICT->{$k} = \(my $x);
1480 } elsif ($k =~ /^\@/) {
1481 0 $STRICT->{$k} = []
1482 } elsif ($k =~ /^\%/) {
1483 0 $STRICT->{$k} = +{};
1484 }
1485 }
1486 }
1487  
1488 # Grab its lexials
1489 0 lexalias($sub, $_, $STRICT->{$_}) for keys %$STRICT;
1490 0 $sub->();
1491 }
1492  
1493 sub repl_eval
1494 0 ▶{
Subroutine repl_eval: not called CC=8 SCAR=40.4
Pod undocumented
1495 0 my ($buf) = @_;
1496 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1497 # local $PACKAGE = $pkg || $PACKAGE;
1498 0 ▶ if ($STRICT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($STRICT) { } 0 0 0
1499 0 my $ctx = join(',', keys %$STRICT);
1500 0 ▶ $ctx = $ctx ? "my ($ctx);" : '';
Branch: 1 branch
BranchTrueFalseTotal
$ctx ? : 0 0 0
1501 0 ▶ if ($WANTARRAY eq '$') {
Branch: 2 branches
BranchTrueFalseTotal
if ($WANTARRAY eq '$') { } 0 0 0
elsif ($WANTARRAY ne '@') { } 0 0 0
1502 0 $buf = 'scalar($buf)';
1503 } elsif ($WANTARRAY ne '@') {
1504 0 $buf = '$buf;1';
1505 }
1506 0 $buf = eval "sub { package $PACKAGE; use strict; $ctx $buf }";
1507 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1508 0 print "ERROR\n$@\n";
1509 0 return;
1510 }
1511 0 call_strict($buf);
1512 } else {
1513 0 $buf = "do { package $PACKAGE; no strict; $buf }";
1514 0 ▶ if ($WANTARRAY eq '@') {
Branch: 2 branches
BranchTrueFalseTotal
if ($WANTARRAY eq '@') { } 0 0 0
elsif ($WANTARRAY eq '$') { } 0 0 0
1515 0 eval $buf;
1516 } elsif ($WANTARRAY eq '$') {
1517 0 scalar eval $buf;
1518 } else {
1519 0 eval $buf; undef
1520 0 }
1521 }
1522 }
1523  
1524 sub repl_test
1525 0 ▶{
Subroutine repl_test: not called CC=6 SCAR=37.4
Pod undocumented
1526 0 my ($buf) = @_;
1527 0 my @files;
1528 0 ▶ if ($buf =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\S/) { } 0 0 0
1529 0 $buf =~ s/^\s+//;
1530 0 $buf =~ s/\s+$//;
1531 0 ▶ if (-f $buf) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $buf) { } 0 0 0
elsif (-f "t/$buf") { } 0 0 0
1532 0 push @files, $buf;
1533 } elsif (-f "t/$buf") {
1534 0 push @files, $buf;
1535 }
1536 } else {
1537 find({ no_chdir => 1,
1538 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1539 0 ▶ push @files, $_ if /\.t$/;
Branch: 1 branch
BranchTrueFalseTotal
if /\.t$/ 0 0 0
1540 0 ▶ }}, Cwd::getcwd() =~ /t\/?$/ ? '.' : './t');
Branch: 1 branch
BranchTrueFalseTotal
Cwd::getcwd() =~ m[t/?$] ? : 0 0 0
1541 }
1542 0 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 0 0 0
1543 # XXX: this is cribbed from an EU::MM-generated Makefile.
1544 0 system $^X, qw(-MExtUtils::Command::MM -e),
1545 "test_harness(0, 'blib/lib', 'blib/arch')", @files;
1546 } else {
1547 0 print "No test files for '$buf' in ", Cwd::getcwd, "\n";
1548 }
1549 }
1550  
1551 sub repl_load
1552 0 ▶{
Subroutine repl_load: not called CC=2 SCAR=17.9
Pod undocumented
1553 0 my ($file) = split ' ', shift;
1554 0 ▶ $file ||= "$ENV{HOME}/.sepia-save";
Condition0%0/2
$file ||= qq[$ENV{"HOME"}/.sepia-save]
l!l
00
MC/DC0%0/1
$file ||= qq[$ENV{"HOME"}/.sepia-save]
$file
Truth table0%0/2
A
A= $file
Aresult
11
00
1555 0 load(retrieve $file);
1556 }
1557  
1558 sub repl_save
1559 0 ▶{
Subroutine repl_save: not called CC=3 SCAR=24.8
Pod undocumented
1560 0 my ($re, $file) = split ' ', shift;
1561 0 ▶ $re ||= '.';
Condition0%0/2
$re ||= "."
l!l
00
MC/DC0%0/1
$re ||= "."
$re
Truth table0%0/2
A
A= $re
Aresult
11
00
1562 0 ▶ $file ||= "$ENV{HOME}/.sepia-save";
Condition0%0/2
$file ||= qq[$ENV{"HOME"}/.sepia-save]
l!l
00
MC/DC0%0/1
$file ||= qq[$ENV{"HOME"}/.sepia-save]
$file
Truth table0%0/2
A
A= $file
Aresult
11
00
1563 0 store save($re), $file;
1564 }
1565  
1566 sub modules_matching
1567 0 ▶{
Subroutine modules_matching: not called CC=3 SCAR=24.8
Pod undocumented
1568 0 my $pat = shift;
1569 0 ▶ if ($pat =~ /^\/(.*)\/?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ m[^/(.*)/?$]) { } 0 0 0
1570 0 $pat = $1;
1571 0 $pat =~ s#::#/#g;
1572 0 $pat = qr/$pat/;
1573 0 grep /$pat/, keys %INC;
1574 } else {
1575 0 my $mod = $pat;
1576 0 $pat =~ s#::#/#g;
1577 0 ▶ exists $INC{"$pat.pm"} ? "$pat.pm" : ();
Branch: 1 branch
BranchTrueFalseTotal
exists $INC{"$pat.pm"} ? : 0 0 0
1578 }
1579 }
1580  
1581 sub full_reload
1582 0 ▶{
Subroutine full_reload: not called CC=4 SCAR=30.0
Pod undocumented
1583 0 my %save_inc = %INC;
1584 0 local %INC;
1585 0 for my $name (modules_matching $_[0]) {
1586 0 print STDERR "full reload $name\n";
1587 0 require $name;
1588 }
1589 0 my @ret = keys %INC;
1590 0 ▶ while (my ($k, $v) = each %save_inc) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %save_inc) 0 0 0
1591 0 ▶ $INC{$k} ||= $v;
Condition0%0/3
$INC{$k} ||= $v
l!l&&r!l&&!r
000
MC/DC0%0/2
$INC{$k} ||= $v
$INC{$k} $v
Truth table0%0/3
A ||= B
A= $INC{$k}B= $v
ABresult
1X1
011
000
1592 }
1593 0 @ret;
1594 }
1595  
1596 sub repl_full_reload
1597 0 ▶{
Subroutine repl_full_reload: not called CC=1 SCAR=6.9
Pod undocumented
1598 0 chomp (my $pat = shift);
1599 0 my @x = full_reload $pat;
1600 0 print "Reloaded: @x\n";
1601 }
1602  
1603 sub repl_reload
1604 0 ▶{
Subroutine repl_reload: not called CC=7 SCAR=40.3
Pod undocumented
1605 0 chomp (my $pat = shift);
1606 # for my $name (modules_matching $pat) {
1607 # delete $INC{$PAT};
1608 # eval "require $name";
1609 # if (!$@) {
1610 # (my $mod = $name) =~ s/
1611 0 ▶ if ($pat =~ /^\/(.*)\/?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ m[^/(.*)/?$]) { } 0 0 0
1612 0 $pat = $1;
1613 0 $pat =~ s#::#/#g;
1614 0 $pat = qr/$pat/;
1615 0 my @rel;
1616 0 for (keys %INC) {
1617 0 ▶ next unless /$pat/;
Branch: 1 branch
BranchTrueFalseTotal
unless /$pat/ 0 0 0
1618 0 ▶ if (!do $_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (do $_) 0 0 0
1619 0 print "$_: $@\n";
1620 }
1621 0 s#/#::#g;
1622 0 s/\.pm$//;
1623 0 push @rel, $_;
1624 }
1625 } else {
1626 0 my $mod = $pat;
1627 0 $pat =~ s#::#/#g;
1628 0 $pat .= '.pm';
1629 0 ▶ if (exists $INC{$pat}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$pat}) { } 0 0 0
1630 0 delete $INC{$pat};
1631 0 eval 'require $mod';
1632 0 ▶ import $mod unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
1633 0 print "Reloaded $mod.\n"
1634 } else {
1635 0 print "$mod not loaded.\n"
1636 }
1637 }
1638 }
1639  
1640 sub repl_lsmod
1641 0 ▶{
Subroutine repl_lsmod: not called CC=8 SCAR=42.8
Pod undocumented
1642 0 chomp (my $pat = shift);
1643 0 ▶ $pat ||= '.';
Condition0%0/2
$pat ||= "."
l!l
00
MC/DC0%0/1
$pat ||= "."
$pat
Truth table0%0/2
A
A= $pat
Aresult
11
00
1644 0 $pat = qr/$pat/;
1645 0 my $first = 1;
1646 0 my $fmt = "%-20s%8s %s\n";
1647 # my $shorten = join '|', sort { length($a) <=> length($b) } @INC;
1648 # my $ss = sub {
1649 # s/^(?:$shorten)\/?//; $_
1650 # };
1651 0 for (sort keys %INC) {
1652 0 my $file = $_;
1653 0 s!/!::!g;
1654 0 s/\.p[lm]$//;
1655 0 ▶ next if /^::/ || !/$pat/;
Branch: 1 branch
BranchTrueFalseTotal
if /^::/ or not /$pat/ 0 0 0
Condition0%0/3
/^::/ or not /$pat/
l!l&&r!l&&!r
000
MC/DC0%0/2
/^::/ or not /$pat/
/^::/ not /$pat/
Truth table0%0/3
A or not(B)
A= /^::/B= not /$pat/
ABresult
1X1
011
000
1656 0 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) 0 0 0
1657 0 printf $fmt, qw(Module Version File);
1658 0 printf $fmt, qw(------ ------- ----);
1659 0 $first = 0;
1660 }
1661 0 ▶ printf $fmt, $_, (UNIVERSAL::VERSION($_)||'???'), $INC{$file};
Condition0%0/2
UNIVERSAL::VERSION($_) || '???'
l!l
00
MC/DC0%0/1
UNIVERSAL::VERSION($_) || '???'
UNIVERSAL::VERSION($_)
Truth table0%0/2
A
A= UNIVERSAL::VERSION($_)
Aresult
11
00
1662 }
1663 0 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) 0 0 0
1664 0 print "No modules found.\n";
1665 }
1666 }
1667  
1668 =item C<sig_warn($warning)>
1669  
1670 Collect C<$warning> for later printing.
1671  
1672 =item C<print_warnings()>
1673  
1674 Print and clear accumulated warnings.
1675  
1676 =cut
1677  
1678 0 my @warn;
1679  
1680 sub sig_warn
1681 0 ▶{
Subroutine sig_warn: not called CC=1 SCAR=6.9
Pod documented
1682 0 push @warn, shift
1683 }
1684  
1685 sub print_warnings
1686 0 ▶{
Subroutine print_warnings: not called CC=4 SCAR=30.0
Pod documented
1687 0 ▶ if (@warn) {
Branch: 1 branch
BranchTrueFalseTotal
if (@warn) 0 0 0
1688 0 ▶ if ($ISEVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Sepia::ISEVAL) { } 0 0 0
1689 0 my $tmp = "@warn";
1690 0 print ';;;'.length($tmp)."\n$tmp\n";
1691 } else {
1692 0 for (@warn) {
1693 # s/(.*) at .*/$1/;
1694 0 print "warning: $_\n";
1695 }
1696 }
1697 }
1698 }
1699  
1700 sub repl_banner
1701 0 ▶{
Subroutine repl_banner: not called CC=1 SCAR=6.9
Pod undocumented
1702 0 print <<EOS;
1703 I need user feedback! Please send questions or comments to seano\@cpan.org.
1704 Sepia version $Sepia::VERSION.
1705 Type ",h" for help, or ",q" to quit.
1706 EOS
1707 }
1708  
1709 =item C<repl()>
1710  
1711 Execute a command interpreter on standard input and standard output.
1712 If you want to use different descriptors, localize them before
1713 calling C<repl()>. The prompt has a few bells and whistles, including:
1714  
1715 =over 4
1716  
1717 =item Obviously-incomplete lines are treated as multiline input (press
1718 'return' twice or 'C-c' to discard).
1719  
1720 =item C<die> is overridden to enter a debugging repl at the point
1721 C<die> is called.
1722  
1723 =back
1724  
1725 Behavior is controlled in part through the following package-globals:
1726  
1727 =over 4
1728  
1729 =item C<$PACKAGE> -- evaluation package
1730  
1731 =item C<$PRINTER> -- result printer (default: dumper)
1732  
1733 =item C<$PS1> -- the default prompt
1734  
1735 =item C<$STRICT> -- whether 'use strict' is applied to input
1736  
1737 =item C<$WANTARRAY> -- evaluation context
1738  
1739 =item C<$COLUMNATE> -- format some output nicely (default = 1)
1740  
1741 Format some values nicely, independent of $PRINTER. Currently, this
1742 displays arrays of scalars as columns.
1743  
1744 =item C<$REPL_LEVEL> -- level of recursive repl() calls
1745  
1746 If zero, then initialization takes place.
1747  
1748 =item C<%REPL> -- maps shortcut names to handlers
1749  
1750 =item C<%REPL_DOC> -- maps shortcut names to documentation
1751  
1752 =item C<%REPL_SHORT> -- maps shortcut names to brief usage
1753  
1754 =back
1755  
1756 =back
1757  
1758 =cut
1759  
1760 sub repl_setup
1761 0 ▶{
Subroutine repl_setup: not called CC=5 SCAR=34.0
Pod undocumented
1762 0 $| = 1;
1763 0 ▶ if ($REPL_LEVEL == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Sepia::REPL_LEVEL == 0) 0 0 0
1764 0 define_shortcuts;
1765 0 ▶ -f "$ENV{HOME}/.sepiarc" and eval qq#package $Sepia::PACKAGE; do "$ENV{HOME}/.sepiarc"#;
Branch: 1 branch
BranchTrueFalseTotal
-f qq[$ENV{"HOME"}/.sepiarc] and eval qq[package $Sepia::PACKAGE; do "$ENV{"HOME"}/.sepiarc"] 0 0 0
1766 0 ▶ warn ".sepiarc: $@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1767 }
1768 0 Sepia::Debug::add_repl_commands;
1769 0 ▶ repl_banner if $REPL_LEVEL == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $Sepia::REPL_LEVEL == 0 0 0 0
1770 }
1771  
1772 0 ▶$READLINE = sub { print prompt(); <STDIN> };
Subroutine __ANON__: not called CC=1 SCAR=2.6
1773  
1774 sub repl
1775 0 ▶{
Subroutine repl: not called CC=23 SCAR=63.1
Pod documented
1776 0 repl_setup;
1777 0 local $REPL_LEVEL = $REPL_LEVEL + 1;
1778  
1779 0 my $in;
1780 0 my $buf = '';
1781 0 $SIGGED = 0;
1782  
1783 0 ▶ my $nextrepl = sub { $SIGGED++; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1784  
1785 0 local (@_, $_);
1786 0 local *CORE::GLOBAL::die = \&Sepia::Debug::die;
1787 0 local *CORE::GLOBAL::warn = \&Sepia::Debug::warn;
1788 0 my @sigs = qw(INT TERM PIPE ALRM);
1789 0 local @SIG{@sigs};
1790 0 $SIG{$_} = $nextrepl for @sigs;
1791 0 ▶ repl: while (defined(my $in = $READLINE->())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $in = &$Sepia::READLINE())) 0 0 0
1792 0 ▶ if ($SIGGED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Sepia::SIGGED) 0 0 0
1793 0 $buf = '';
1794 0 $SIGGED = 0;
1795 0 print "\n";
1796 0 next repl;
1797 }
1798 0 $buf .= $in;
1799 0 $buf =~ s/^\s*//;
1800 0 local $ISEVAL;
1801 0 ▶ if ($buf =~ /^<<(\d+)\n(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /^<<(\d+)\n(.*)/) 0 0 0
1802 0 $ISEVAL = 1;
1803 0 my $len = $1;
1804 0 my $tmp;
1805 0 $buf = $2;
1806 0 ▶ while ($len && defined($tmp = read STDIN, $buf, $len, length $buf)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len and defined($tmp = read(STDIN, $buf, $len, length $buf))) 0 0 0
Condition0%0/3
$len and defined($tmp = read(STDIN, $buf, $len, length $buf))
!ll&&!rl&&r
000
MC/DC0%0/2
$len and defined($tmp = read(STDIN, $buf, $len, length $buf))
$len defined($tmp = read(STDIN, $buf, $len, length $buf))
Truth table0%0/3
A and B
A= $lenB= defined($tmp = read(STDIN, $buf, $len, length $buf))
ABresult
0X0
100
111
1807 0 $len -= $tmp;
1808 }
1809 }
1810 ## Only install a magic handler if no one else is playing.
1811 0 local $SIG{__WARN__} = $SIG{__WARN__};
1812 0 @warn = ();
1813 0 ▶ unless ($SIG{__WARN__}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($SIG{"__WARN__"}) 0 0 0
1814 0 $SIG{__WARN__} = 'Sepia::sig_warn';
1815 }
1816 0 ▶ if (!$ISEVAL) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Sepia::ISEVAL) 0 0 0
1817 0 ▶ if ($buf eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf eq '') { } 0 0 0
1818 # repeat last interactive command
1819 0 $buf = $LAST_INPUT;
1820 } else {
1821 0 $LAST_INPUT = $buf;
1822 }
1823 }
1824 0 ▶ if ($buf =~ /^,(\S+)\s*(.*)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /^,(\S+)\s*(.*)/s) { } 0 0 0
1825 ## Inspector shortcuts
1826 0 my $short = $1;
1827 0 ▶ if (exists $Sepia::RK{$short}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Sepia::RK{$short}) { } 0 0 0
1828 0 my $ret;
1829 0 my $arg = $2;
1830 0 chomp $arg;
1831 0 $Sepia::REPL{$Sepia::RK{$short}}->($arg, wantarray);
1832 } else {
1833 0 ▶ if (grep /^$short/, keys %Sepia::REPL) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$short/, keys %Sepia::REPL) { } 0 0 0
1834 0 print "Ambiguous shortcut '$short': ",
1835 join(', ', sort grep /^$short/, keys %Sepia::REPL),
1836 "\n";
1837 } else {
1838 0 print "Unrecognized shortcut '$short'\n";
1839 }
1840 0 $buf = '';
1841 0 next repl;
1842 }
1843 } else {
1844 ## Ordinary eval
1845 0 run_hook @PRE_EVAL;
1846 0 @res = $REPL{eval}->($buf);
1847 0 run_hook @POST_EVAL;
1848 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1849 0 ▶ if ($ISEVAL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Sepia::ISEVAL) { } 0 0 0
elsif ($@ =~ /(?:at|before) EOF(?:$| at)/m) { } 0 0 0
1850 ## Always return results for an eval request
1851 0 Sepia::printer \@res, wantarray;
1852 0 Sepia::printer [$@], wantarray;
1853 # print_warnings $ISEVAL;
1854 0 $buf = '';
1855 } elsif ($@ =~ /(?:at|before) EOF(?:$| at)/m) {
1856 ## Possibly-incomplete line
1857 0 ▶ if ($in eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($in eq "\n") { } 0 0 0
1858 0 print "Error:\n$@\n*** cancel ***\n";
1859 0 $buf = '';
1860 } else {
1861 0 print ">> ";
1862 }
1863 } else {
1864 0 print_warnings;
1865 # $@ =~ s/(.*) at eval .*/$1/;
1866 # don't complain if we're abandoning execution
1867 # from the debugger.
1868 0 ▶ unless (ref $@ eq 'Sepia::Debug') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $@ eq "Sepia::Debug") 0 0 0
1869 0 print "error: $@";
1870 0 ▶ print "\n" unless $@ =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ =~ /\n\z/ 0 0 0
1871 }
1872 0 $buf = '';
1873 }
1874 0 next repl;
1875 }
1876 }
1877 0 ▶ if ($buf !~ /;\s*$/ && $buf !~ /^,/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($buf =~ /;\s*$/ or $buf =~ /^,/) 0 0 0
Condition0%0/3
$buf =~ /;\s*$/ or $buf =~ /^,/
l!l&&r!l&&!r
000
MC/DC0%0/2
$buf =~ /;\s*$/ or $buf =~ /^,/
$buf =~ /;\s*$/ $buf =~ /^,/
Truth table0%0/3
A or B
A= $buf =~ /;\s*$/B= $buf =~ /^,/
ABresult
1X1
011
000
1878 ## Be quiet if it ends with a semicolon, or if we
1879 ## executed a shortcut.
1880 0 Sepia::printer \@res, wantarray;
1881 }
1882 0 $buf = '';
1883 0 print_warnings;
1884 }
1885 0 ▶ exit if $REPL_QUIT;
Branch: 1 branch
BranchTrueFalseTotal
if $Sepia::REPL_QUIT 0 0 0
1886 0 ▶ wantarray ? @res : $res[0]
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1887 }
1888  
1889 sub perl_eval
1890 0 ▶{
Subroutine perl_eval: not called CC=1 SCAR=6.9
Pod undocumented
1891 0 tolisp($REPL{eval}->(shift));
1892 }
1893  
1894 =head2 Module browsing
1895  
1896 =over
1897  
1898 =item C<$status = html_module_list([$file [, $prefix]])>
1899  
1900 Generate an HTML list of installed modules, looking inside of
1901 packages. If C<$prefix> is missing, uses "about://perldoc/". If
1902 $file is given, write the result to $file; otherwise, return it as a
1903 string.
1904  
1905 =item C<$status = html_package_list([$file [, $prefix]])>
1906  
1907 Generate an HTML list of installed top-level modules, without looking
1908 inside of packages. If C<$prefix> is missing, uses
1909 "about://perldoc/". $file is the same as for C<html_module_list>.
1910  
1911 =back
1912  
1913 =cut
1914  
1915 sub html_module_list
1916 0 ▶{
Subroutine html_module_list: not called CC=22 SCAR=62.3
Pod documented
1917 0 my ($file, $base) = @_;
1918 0 ▶ $base ||= 'about://perldoc/';
Condition0%0/2
$base ||= "about://perldoc/"
l!l
00
MC/DC0%0/1
$base ||= "about://perldoc/"
$base
Truth table0%0/2
A
A= $base
Aresult
11
00
1919 0 my $inst = inst();
1920 0 ▶ return unless $inst;
Branch: 1 branch
BranchTrueFalseTotal
unless $inst 0 0 0
1921 0 my $out;
1922 0 ▶ open OUT, ">", $file || \$out or return;
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">", $file || \$out or return 0 0 0
Condition0%0/2
$file || \$out
l!l
00
MC/DC0%0/1
$file || \$out
$file
Truth table0%0/2
A
A= $file
Aresult
11
00
1923 0 print OUT "<html><body>";
1924 0 my $pfx = '';
1925 0 my %ns;
1926 0 for (package_list) {
1927 0 ▶ push @{$ns{$1}}, $_ if /^([^:]+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^([^:]+)/ 0 0 0
1928 }
1929 # Handle core modules.
1930 0 my %fs;
1931 0 undef $fs{$_} for map {
1932 0 s/.*man.\///; s|/|::|g; s/\.\d(?:pm)?$//; $_
1933 } grep {
1934 0 ▶ /\.\d(?:pm)?$/ && !/man1/ && !/usr\/bin/ # && !/^(?:\/|perl)/
Condition0%0/6
/\.\d(?:pm)?$/ && !/man1/ && !m[usr/bin]
!ll&&!rl&&r
000
/\.\d(?:pm)?$/ and not /man1/
!ll&&!rl&&r
000
MC/DC0%0/3
/\.\d(?:pm)?$/ && !/man1/ && !m[usr/bin]
/\.\d(?:pm)?$/ not /man1/ !m[usr/bin]
Truth table0%0/4
A and not(B) && not(C)
A= /\.\d(?:pm)?$/B= not /man1/C= !m[usr/bin]
ABCresult
0XX0
10X0
1100
1111
1935 } $inst->files('Perl');
1936 0 my @fs = sort keys %fs;
1937 0 print OUT qq{<h2>Core Modules</h2><ul>};
1938 0 for (@fs) {
1939 0 print OUT qq{<li><a href="$base$_">$_</a>};
1940 }
1941 0 print OUT '</ul><h2>Installed Modules</h2><ul>';
1942  
1943 # handle the rest
1944 0 for (sort keys %ns) {
1945 0 ▶ next if $_ eq 'Perl'; # skip Perl core.
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "Perl" 0 0 0
1946 0 ▶ print OUT qq{<li><b>$_</b><ul>} if @{$ns{$_}} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$ns{$_};} > 1 0 0 0
1947 0 for (sort @{$ns{$_}}) {
1948 0 my %fs;
1949 0 undef $fs{$_} for map {
1950 0 s/.*man.\///; s|/|::|g; s/\.\d(?:pm)?$//; $_
1951 } grep {
1952 0 ▶ /\.\d(?:pm)?$/ && !/man1/
Condition0%0/3
/\.\d(?:pm)?$/ && !/man1/
!ll&&!rl&&r
000
MC/DC0%0/2
/\.\d(?:pm)?$/ && !/man1/
/\.\d(?:pm)?$/ !/man1/
Truth table0%0/3
A && not(B)
A= /\.\d(?:pm)?$/B= !/man1/
ABresult
0X0
100
111
1953 } $inst->files($_);
1954 0 my @fs = sort keys %fs;
1955 0 ▶ next unless @fs > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @fs > 0 0 0 0
1956 0 ▶ if (@fs == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fs == 1) { } 0 0 0
1957 0 print OUT qq{<li><a href="$base$fs[0]">$fs[0]</a>};
1958 } else {
1959 0 print OUT qq{<li>$_<ul>};
1960 0 for (@fs) {
1961 0 print OUT qq{<li><a href="$base$_">$_</a>};
1962 }
1963 0 print OUT '</ul>';
1964 }
1965 }
1966 0 ▶ print OUT qq{</ul>} if @{$ns{$_}} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$ns{$_};} > 1 0 0 0
1967 }
1968  
1969 0 print OUT "</ul></body></html>\n";
1970 0 close OUT;
1971 0 ▶ $file ? 1 : $out;
Branch: 1 branch
BranchTrueFalseTotal
$file ? : 0 0 0
1972 }
1973  
1974 sub html_package_list
1975 0 ▶{
Subroutine html_package_list: not called CC=11 SCAR=48.8
Pod documented
1976 0 my ($file, $base) = @_;
1977 0 ▶ return unless inst();
Branch: 1 branch
BranchTrueFalseTotal
unless &inst() 0 0 0
1978 0 my %ns;
1979 0 for (package_list) {
1980 0 ▶ push @{$ns{$1}}, $_ if /^([^:]+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^([^:]+)/ 0 0 0
1981 }
1982 0 ▶ $base ||= 'about://perldoc/';
Condition0%0/2
$base ||= "about://perldoc/"
l!l
00
MC/DC0%0/1
$base ||= "about://perldoc/"
$base
Truth table0%0/2
A
A= $base
Aresult
11
00
1983 0 my $out;
1984 0 ▶ open OUT, ">", $file || \$out or return;
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">", $file || \$out or return 0 0 0
Condition0%0/2
$file || \$out
l!l
00
MC/DC0%0/1
$file || \$out
$file
Truth table0%0/2
A
A= $file
Aresult
11
00
1985 0 print OUT "<html><body><ul>";
1986 0 my $pfx = '';
1987 0 for (sort keys %ns) {
1988 0 ▶ if (@{$ns{$_}} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$ns{$_};} == 1) { } 0 0 0
1989 0 print OUT
1990 qq{<li><a href="$base$ns{$_}[0]">$ns{$_}[0]</a>};
1991 } else {
1992 0 print OUT qq{<li><b>$_</b><ul>};
1993 print OUT qq{<li><a href="$base$_">$_</a>}
1994 0 for sort @{$ns{$_}};
1995 0 print OUT qq{</ul>};
1996 }
1997 }
1998 0 print OUT "</ul></body></html>\n";
1999 0 close OUT;
2000 0 ▶ $file ? 1 : $out;
Branch: 1 branch
BranchTrueFalseTotal
$file ? : 0 0 0
2001 }
2002  
2003 sub apropos_module
2004 0 ▶{
Subroutine apropos_module: not called CC=6 SCAR=37.4
Pod undocumented
2005 0 my $re = _apropos_re $_[0], 1;
2006 0 my $inst = inst();
2007 0 my %ret;
2008 0 my $incre = inc_re;
2009 0 for ($inst->files('Perl', 'prog'), package_list) {
2010 0 ▶ if (/\.\d?(?:pm)?$/ && !/man1/ && !/usr\/bin/ && /$re/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\.\d?(?:pm)?$/ and not /man1/ and not m[usr/bin] and /$re/) 0 0 0
Condition0%0/9
/\.\d?(?:pm)?$/ and not /man1/ and not m[usr/bin] and /$re/
!ll&&!rl&&r
000
/\.\d?(?:pm)?$/ and not /man1/ and not m[usr/bin]
!ll&&!rl&&r
000
/\.\d?(?:pm)?$/ and not /man1/
!ll&&!rl&&r
000
MC/DC0%0/4
/\.\d?(?:pm)?$/ and not /man1/ and not m[usr/bin] and /$re/
/\.\d?(?:pm)?$/ not /man1/ not m[usr/bin] /$re/
Truth table0%0/5
A and not(B) and not(C) and D
A= /\.\d?(?:pm)?$/B= not /man1/C= not m[usr/bin]D= /$re/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2011 0 s/$incre//;
2012 0 s/.*man.\///;
2013 0 s|/|::|g;
2014 0 s/^:+//;
2015 0 s/\.\d?(?:p[lm])?$//;
2016 0 undef $ret{$_}
2017 }
2018 }
2019 0 sort keys %ret;
2020 }
2021  
2022 sub requires
2023 0 ▶{
Subroutine requires: not called CC=2 SCAR=17.9
Pod undocumented
2024 0 my $mod = shift;
2025 0 my @q = $REQUIRES{$mod};
2026 0 my @done;
2027 0 ▶ while (@q) {
Branch: 1 branch
BranchTrueFalseTotal
if (@q) 0 0 0
2028 0 my $m = shift @q;
2029 0 push @done, $m;
2030 0 push @q, @{$REQUIRES{$m}};
2031 }
2032 0 @done;
2033 }
2034  
2035 sub users
2036 0 ▶{
Subroutine users: not called CC=1 SCAR=6.9
Pod undocumented
2037 0 my $mod = shift;
2038 0 @{$REQUIRED_BY{$mod}}
2039 }
2040  
2041 2 1;
2042 __END__
↑ Summary Sepia/Xref.pm »