blib/lib/PDL/Graphics/State.pm

filter: Statementstmt 2.8% 1 / 35 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 8 totaltotal 1.7% 1 / 57 CC 4 SCAR 13.9
CC
4
Cov
3%
new
6.0
show
6.0
copy
6.0
CRAP 4.0
« blib/lib/PDL/Perldl2/Plugin/PrintControl.pm ↑ Summary blib/lib/PDL/PP/Dims.pm »
1 =head1 NAME
2  
3 State - A package to keep track of plotting commands
4  
5 =head1 SYNOPSIS
6  
7 use PDL::Graphics::State;
8  
9 =head1 DESCRIPTION
10  
11 This is a very simple, at present almost trivial, package to keep track
12 of the current set of plotting commands.
13  
14 =head1 USAGE
15  
16 You create a new object by calling the C<new> operator
17  
18 $state = PDL::Graphics::State->new();
19  
20 Then for each new command you call C<add> on this object so that for a
21 call to C<line> of the form
22  
23 line $x, $y, $opt;
24  
25 the call to C<add> would be like
26  
27 $state->add(\&line, 'line', [$x, $y], $opt);
28  
29 which is stored internally as:
30  
31 [\&line, 'line', [$x, $y], $opt]
32  
33 The state can later be extracted using C<get> which returns the state
34 object which is an array of anonymous arrays like the one above where
35 the first object is a reference to the function, the second an anomymous
36 array of arguments to the function and finally an anonymous hash with
37 options to the command.
38  
39 If you know the order in which you inserted commands they can be removed
40 by calling C<remove> with the number in the stack. No further interaction
41 is implemented except C<clear> which clears the stack and C<copy> which
42 returns a "deep" copy of the state.
43  
44  
45  
46 =head1 AUTHOR
47  
48 Jarle Brinchmann (jarle@astro.ox.ac.uk) after some prodding by
49 Karl Glazebrook.
50  
51 All rights reserved. There is no warranty. You are allowed
52 to redistribute this software / documentation under certain
53 conditions. For details, see the file COPYING in the PDL
54 distribution. If this file is separated from the PDL distribution,
55 the copyright notice should be included in the file.
56  
57  
58 =cut
59  
60 package PDL::Graphics::State;
61  
62 #
63 # This is a very simple package to deal with the graphics state.
64 #
65  
66 sub new {
67 0 ▶ my $type = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
68  
69 0 my $self = {
70 'Commands' => [],
71 };
72  
73 0 ▶ bless $self, ref($type) || $type;
Condition0%0/3
ref $type || $type
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $type || $type
ref $type $type
Truth table0%0/3
A || B
A= ref $typeB= $type
ABresult
1X1
011
000
74 0 return $self;
75 }
76  
77  
78 sub DESTROY {
79 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=1 SCAR=6.9
80 0 $self->clear();
81 }
82  
83 sub add {
84 0 ▶ my $self = shift;
Subroutine add: not called CC=1 SCAR=6.9
Pod undocumented
85 # The command is a reference to the subroutine, the data is an
86 # anonymous array containing the data passed to the routine and
87 # opt is the options hash PASSED TO THE ROUTINE..
88 0 my ($command, $command_name, $data, $opt) = @_;
89  
90 # Compact and not user-friendly storage.
91 0 push @{$self->{Commands}}, [$command, $command_name, $data, $opt];
92  
93 # return $#{$self->{Commands}}+1;
94 }
95  
96  
97 sub remove {
98 0 ▶ my $self = shift;
Subroutine remove: not called CC=1 SCAR=6.9
Pod undocumented
99 0 my $num = shift;
100  
101 # Remove entry #1
102 0 splice @{$self->{Commands}}, $num, 1;
103 }
104  
105 sub get {
106 0 ▶ my $self = shift;
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
107 0 return @{$self->{Commands}};
108 }
109  
110 sub info {
111 0 ▶ my $self = shift;
Subroutine info: not called CC=1 SCAR=6.9
Pod undocumented
112 0 print "The state has ".($#{$self->{Commands}}+1)." commands in the stack\n";
113 }
114  
115 sub show {
116 0 ▶ my $self = shift;
Subroutine show: not called CC=2 SCAR=17.9
Pod undocumented
117 0 my $count=0;
118 0 foreach my $arg (@{$self->{Commands}}) {
119 0 print "$count - Func=$$arg[1]\n";
120 0 $count++;
121 }
122  
123 }
124  
125 sub clear {
126 0 ▶ my $self = shift;
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
127 # Do I need to do more?
128 0 $self->{Commands}=[];
129 }
130  
131  
132 sub copy {
133 0 ▶ my $self = shift;
Subroutine copy: not called CC=2 SCAR=17.9
Pod undocumented
134 0 my $new = PDL::Graphics::State->new();
135 0 foreach my $arg (@{$self->{Commands}}) {
136 0 $new->add(@$arg);
137 }
138 0 return $new;
139 }
140  
141 1 1;
« blib/lib/PDL/Perldl2/Plugin/PrintControl.pm ↑ Summary blib/lib/PDL/PP/Dims.pm »