File Coverage

blib/lib/Chart/Graph/Xmgrace/Base_Option.pm
Criterion Covered Total %
statement 45 50 90.0
branch 11 14 78.5
condition 5 12 41.6
subroutine 5 5 100.0
pod 0 2 0.0
total 66 83 79.5


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