blib/lib/PDL/Dbg.pm

filter: Statementstmt 48.7% 20 / 41 Branchbran 22.2% 4 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 43.7% 28 / 64 CC 12 SCAR 39.5
CC
12
Cov
41%
px
64.5
BEGIN
1.1
BEGIN
1.0
CRAP 51.8
« blib/lib/PDL/IO/Pic.pm ↑ Summary blib/lib/PDL/NiceSlice/FilterUtilCall.pm »
1 =head1 NAME
2  
3 PDL::Dbg - functions to support debugging of PDL scripts
4  
5 =head1 SYNOPSIS
6  
7 use PDL;
8 use PDL::Dbg;
9  
10 $c = $x->slice("5:10,2:30")->px->diagonal(3,4);
11 PDL->px;
12  
13 =head1 DESCRIPTION
14  
15 These packages implements a couple of functions that should come in
16 handy when debugging your PDL scripts. They make a lot of sense while
17 you're doing rapid prototyping of new PDL code, let's say inside the
18 perldl shell.
19  
20 =cut
21  
22 #' fool emacs
23  
24 package PDL::Dbg;
25  
26 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 # used by info
29 7 our $Title = "Type Dimension State Mem";
30 7 our $Infostr = "%6T %-15D %-5S %12M";
31  
32 package # hide from MetaCPAN
33 PDL;
34  
35 =head1 FUNCTIONS
36  
37 =head2 px
38  
39 =for ref
40  
41 Print info about an ndarray (or all known ndarrays)
42  
43 =for example
44  
45 pdl> PDL->px
46 pdl> $y += $x->clump(2)->px('clumptest')->sumover
47 pdl> $x->px('%C (%A) Type: %T') # prints nothing unless $PDL::debug
48 pdl> $PDL::debug = 1
49 pdl> $x->px('%C (%A) Type: %T')
50 PDL (52433464) Type: Double
51  
52  
53 This function prints some information about ndarrays. It can be invoked
54 as a class method (e.g. C<PDL-E<gt>px> ) or as an instance method (e.g.
55 C<$pdl-E<gt>px($arg)>). If
56  
57 =over 2
58  
59 =item invoked as a class method
60  
61 it prints info about all ndarrays found in the current package
62 (I<excluding> C<my> variables). This comes in quite handy when you are
63 not quite sure which pdls you have already defined, what data they
64 hold , etc. C<px> is supposed to support inheritance and prints info
65 about all symbols for which an C<isa($class)> is true. An optional
66 string argument is interpreted as the package name for which to print
67 symbols:
68  
69 pdl> PDL->px('PDL::Mypack')
70  
71 The default package is that of the caller.
72  
73 =item invoked as an instance method
74  
75 it prints info about that particular ndarray if C<$PDL::debug> is
76 true and returns the pdl object upon completion. It accepts an
77 optional string argument that is simply prepended to the default info
78 if it doesn't contain a C<%> character. If, however, the argument
79 contains a C<%> then the string is passed to the C<info> method to
80 control the format of the printed information. This can be used to
81 achieve customized output from C<px>. See the documentation of
82 C<PDL::info> for further details.
83  
84 =back
85  
86 The output of px will be determined by the default formatting string
87 that is passed to the C<info> method (unless you pass a string
88 containing C<%> to px when invoking as an instance method, see
89 above). This default string is stored in C<$PDL::Dbg::Infostr> and the
90 default output format can be accordingly changed by setting this
91 variable. If you do this you should also change the default title
92 string that the class method branch prints at the top of the listing
93 to match your new format string. The default title is stored in the
94 variable C<$PDL::Dbg::Title>.
95  
96 For historical reasons C<vars> is an alias for C<px>.
97  
98 =cut
99  
100 7 ▶sub px :lvalue {
Subroutine px: called CC=12 SCAR=41.7
Pod undocumented
101 7 my $arg = shift;
102 7 my $str="";
103  
104 7 ▶ if (ref($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg) 7 0 7
105 7 ▶ return $arg unless $PDL::debug;
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::debug 1 6 7
106 6 ▶ my $info = $arg->info($#_ > -1 ? ($_[0] =~ /%/ ?
Branch: 2 branches
BranchTrueFalseTotal
$#_ > -1 ? : 0 6 6
$_[0] =~ /%/ ? : 0 0 0
107 $_[0] : "$_[0] $PDL::Dbg::Infostr") :
108 $PDL::Dbg::Infostr);
109 6 print "$info\n";
110 6 return $arg;
111 }
112  
113 # we have been called as a class method
114 0 ▶ my $package = $#_ > -1 ? shift : caller;
Branch: 1 branch
BranchTrueFalseTotal
$#_ > -1 ? : 0 0 0
115 0 my $classname = $arg;
116 # find the correct package
117 0 ▶ $package .= "::" unless $package =~ /::$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $package =~ /::$/ 0 0 0
118 0 my $stab = \%main::;
119 0 $stab = $stab->{$_.'::'} for grep length, split /::/, $package;
120 0 print "$classname variables in package $package\n\n";
121 0 my $title = "Name $PDL::Dbg::Title\n";
122 0 print $title;
123 0 print '-'x(length($title)+3)."\n";
124 0 my $npdls = 0;
125 0 foreach my $key ( sort { lc($a) cmp lc($b) } keys %$stab ) {
126 0 ▶ my $pdl = do { no strict 'refs'; ${"$package$key"} };
Subroutine BEGIN: called CC=1 SCAR=1.2
127 0 ▶ next if !UNIVERSAL::isa($pdl,$classname);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($pdl, $classname) 0 0 0
128 # print info for all objects derived from this class
129 0 $npdls++;
130 0 my $info = $pdl->info($Infostr);
131 0 ▶ printf "\$%-11s %s %s\n",$key,$info,(ref $pdl eq $classname ? '' :
Branch: 1 branch
BranchTrueFalseTotal
ref $pdl eq $classname ? : 0 0 0
132 ref $pdl);
133 # also print classname for derived classes
134 }
135 0 ▶ print "no $classname objects in package $package\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $npdls 0 0 0
136 unless $npdls;
137 0 return $arg;
138 }
139  
140 =head2 vars
141  
142 =for ref
143  
144 Alias for C<px>
145  
146 =cut
147  
148 7 *vars = \&px;
149  
150 7 1; # return success
151  
152 =head1 BUGS
153  
154 There are probably some. Please report if you find any. Bug reports
155 should be sent to the PDL mailing list pdl-general@lists.sourceforge.net.
156  
157 =head1 AUTHOR
158  
159 Copyright(C) 1997 Christian Soeller (c.soeller@auckland.ac.nz).
160 All rights reserved. There is no warranty. You are allowed
161 to redistribute this software / documentation under certain
162 conditions. For details, see the file COPYING in the PDL
163 distribution. If this file is separated from the PDL distribution,
164 the copyright notice should be included in the file.
165  
166  
« blib/lib/PDL/IO/Pic.pm ↑ Summary blib/lib/PDL/NiceSlice/FilterUtilCall.pm »