File Coverage

blib/lib/Chart/Graph/Xmgrace/Base_Dataset_Option.pm
Criterion Covered Total %
statement 17 55 30.9
branch 3 22 13.6
condition 3 15 20.0
subroutine 3 5 60.0
pod 0 2 0.0
total 26 99 26.2


line stmt bran cond sub pod time code
1             ## This software product is developed by Esmond Lee and David Moore,
2             ## and copyrighted(C) 1998 by the University of California, San Diego
3             ## (UCSD), with all rights reserved. UCSD administers the CAIDA grant,
4             ## NCR-9711092, under which part of this code was developed.
5             ##
6             ## There is no charge for this software. You can redistribute it and/or
7             ## modify it under the terms of the GNU General Public License, v. 2 dated
8             ## June 1991 which is incorporated by reference herein. This software is
9             ## distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF MERCHANTABILITY
10             ## OR FITNESS FOR A PARTICULAR PURPOSE or that the use of it will not
11             ## infringe on any third party's intellectual property rights.
12             ##
13             ## You should have received a copy of the GNU GPL along with this program.
14             ##
15             ##
16             ## IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
17             ## PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
18             ## DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
19             ## SOFTWARE, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF
20             ## THE POSSIBILITY OF SUCH DAMAGE.
21             ##
22             ## THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE
23             ## UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
24             ## SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. THE UNIVERSITY
25             ## OF CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES
26             ## OF ANY KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED
27             ## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
28             ## PARTICULAR PURPOSE, OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE
29             ## ANY PATENT, TRADEMARK OR OTHER RIGHTS.
30             ##
31             ##
32             ## Contact: graph-dev@caida.org
33             ##
34             ##
35             $VERSION = 3.2;
36              
37             package Chart::Graph::Xmgrace::Base_Dataset_Option;
38 4     4   24 use Carp;
  4         46  
  4         3507  
39              
40             sub new {
41 480     480 0 568 my $this = shift;
42 480   33     1446 my $class = ref($this) || $this;
43 480         635 my $self = {};
44 480         1061 bless $self, $class;
45 480         1372 $self->_init(@_);
46 480         2121 return $self;
47             }
48              
49             #
50             #
51             # Subroutine: _printline()
52             #
53             # Description: this function will print out a line that can be
54             # read with xmgrace (with the prepended @)
55             #
56             #
57             #
58            
59             sub _printline ($$$$ ) {
60 0     0   0 my $self = shift;
61 0         0 my ($handle, $string, $length) = @_;
62              
63 0 0       0 if (!$string) {
64 0         0 print $handle "error: no string to print!\n";
65 0         0 return 0;
66             }
67              
68 0         0 print $handle "@";
69 0         0 print $handle ' ' x $length;
70 0         0 print $handle "$string";
71              
72 0         0 return 1; # just for fun
73             }
74              
75             sub print($$$ ) {
76 0     0 0 0 my $self = shift;
77 0         0 my ($handle, $set) = @_;
78 0         0 my $string = "";
79            
80 0         0 foreach $option (@{ $self->{"print_order"} }) {
  0         0  
81 0         0 my $option_ref = $self->{"options"};
82              
83 0 0 0     0 if ($option eq "status" or $option eq "in_out_status") {
84            
85             # we first check the status of the option, whether it's on/off
86             # if it's off, we don't print it out
87 0 0       0 if ($option_ref->{"status"} eq "off") {
88 0         0 $string = "$set $self->{name} $option_ref->{$option}\n";
89 0         0 $self->_printline($handle, $string, $self->{"length"});
90 0         0 last;
91             }
92 0         0 $string = "$set $self->{name} $option_ref->{$option}\n";
93 0         0 $self->_printline($handle, $string, $self->{"length"});
94              
95             } else {
96              
97             # we skip hidden datasets
98 0 0       0 if ($option eq "hidden") {
99 0 0       0 if ($option_ref->{"hidden"} eq "true") {
100 0         0 last;
101             }
102             }
103              
104 0 0       0 if (!ref($option_ref->{$option})) {
    0          
105 0 0 0     0 if ($option eq "comment" or $option eq "legend") {
    0          
106 0         0 $string = "$set $option \"$option_ref->{$option}\"\n";
107             } elsif (!$self->{name}) {
108 0         0 $string = "$set $option $option_ref->{$option}\n";
109             } else {
110 0         0 $string = "$set $self->{name} $option $option_ref->{$option}\n";
111             }
112            
113             } elsif (ref($option_ref->{$option}) eq ARRAY) {
114 0         0 $substr = join (", ", (@{ $option_ref->{$option} }));
  0         0  
115 0         0 $string = "$set $self->{name} $option $substr\n";
116             } else { # a blessed object, use own print function (which in this case is the same)
117 0         0 $option_ref->{$option}->print($handle, $set);
118 0         0 next;
119             }
120              
121 0         0 $self->_printline($handle, $string, $self->{"length"});
122 0         0 $string = "";
123             }
124             }
125             }
126              
127             sub AUTOLOAD {
128 150     150   178 my $self = shift;
129 150   33     652 my $type = ref($self) || croak "$self is not an object";
130 150         677 my $name = $AUTOLOAD;
131 150         1020 $name =~ s/.*://; #strip fully-qualified portion
132 150 50 33     1208 unless (($name eq "DESTROY") or (exists $self->{options}->{$name})) {
133 0         0 croak "Can't access '$name' field in object of class $type";
134             }
135              
136 150 100       663 if (@_) {
137 60         352 return $self->{options}->{$name} = shift;
138             } else {
139 90         1351 return $self->{options}->{$name};
140             }
141             }
142              
143             1;