File Coverage

blib/lib/Autodia/Diagram/Object.pm
Criterion Covered Total %
statement 6 77 7.7
branch 0 8 0.0
condition 0 17 0.0
subroutine 2 18 11.1
pod 0 11 0.0
total 8 131 6.1


line stmt bran cond sub pod time code
1             ################################################################
2             # AutoDia - Automatic Dia XML. (C)Copyright 2001 A Trevena #
3             # #
4             # AutoDia comes with ABSOLUTELY NO WARRANTY; see COPYING file #
5             # This is free software, and you are welcome to redistribute #
6             # it under certain conditions; see COPYING file for details #
7             ################################################################
8             package Autodia::Diagram::Object;
9              
10 1     1   7 use strict;
  1         2  
  1         41  
11              
12             require Exporter;
13 1     1   5 use vars qw($VERSION @ISA @EXPORT);
  1         2  
  1         1070  
14              
15             @ISA = qw(Exporter);
16              
17              
18             #---------------------------------------------------------------
19              
20             #####################
21             # Constructor Methods
22              
23             sub new
24             {
25 0     0 0   my $class = shift;
26 0           my $self = {};
27              
28 0   0       bless ($self, ref($class) || $class);
29 0           $self->_initialise();
30              
31 0           return $self;
32             }
33              
34             #------------------------------------------------------------------------
35             # Access Methods
36              
37             sub set_location
38             {
39 0     0 0   my $self = shift;
40 0   0       my $new_x = shift || 1;
41 0   0       my $new_y = shift || 1;
42              
43 0 0         if (defined $new_x )
44             {
45 0           $self->{"left_x"} = $new_x;
46 0           $self->{"top_y"} = $new_y;
47             }
48 0           my @bottom_right_xy = split(",",$self->BottomRightPos);
49              
50 0           return \@bottom_right_xy;
51             }
52              
53             sub TopLeftPos
54             {
55 0     0 0   my $self = shift;
56 0           my $return = sprintf("%.3f",$self->{"left_x"}) . "," . sprintf("%.3f",$self->{"top_y"});
57 0           return $return;
58             }
59              
60             sub BottomRightPos
61             {
62 0     0 0   my $self = shift;
63              
64              
65 0   0       $self->{"left_x"} ||= 1; # hack
66 0   0       $self->{"width"} ||= 1; # these aren't getting initialised for some reason
67 0   0       $self->{"top_y"} ||= 1;
68 0   0       $self->{"height"} ||= 1;
69              
70 0           my $x = sprintf("%.3f",$self->{"width"} + $self->{"left_x"});
71 0           my $y = sprintf("%.3f",$self->{"top_y"} + $self->{"height"});
72              
73 0           return "$x,$y";
74             }
75              
76             sub Width
77             {
78 0     0 0   my $self = shift;
79 0           return sprintf("%.3f",$self->{"width"});
80             }
81              
82             sub Height
83             {
84 0     0 0   my $self = shift;
85 0           return sprintf("%.3f",$self->{"height"});
86             }
87              
88             sub Id
89             {
90 0     0 0   my $self = shift;
91 0           return $self->{"id"};
92             }
93              
94             sub Set_Id
95             {
96 0     0 0   my $self = shift;
97 0           $self->{"id"} = shift;
98 0           return 1;
99             }
100              
101             sub Type
102             {
103 0     0 0   my $self = shift;
104 0           my $return_val = "-";
105 0   0       my $type = $self->{"type"} || 0;
106 0 0         if ($type) { $return_val = $type; }
  0            
107 0           return $return_val;
108             }
109              
110             sub Name
111             {
112 0     0 0   my $self = shift;
113 0           my $name = shift;
114 0 0         if ($name)
115             {
116 0           $self->{"name"} = $name;
117 0           return 1;
118             }
119             else
120             {
121 0           return $self->{"name"};
122             }
123             }
124              
125             sub LocalId
126             {
127 0     0 0   my $self = shift;
128 0           my $new_id = shift;
129 0           my $return = 1;
130              
131 0 0         if (defined $new_id)
132 0           { $self->{"local_id"} = $new_id; }
133             else
134 0           { $return = $self->{"local_id"}; }
135              
136 0           return $return;
137             }
138              
139             #-----------------------------------------------------------------------------
140             # Internal Methods
141              
142             sub _initialise
143             {
144 0     0     my $self = shift;
145 0           $self->{"width"} = 1;
146 0           $self->{"height"} = 1;
147 0           $self->{"name"} = "";
148 0           $self->{"top_y"} = 0;
149 0           $self->{"left_x"} = 0;
150 0           return;
151             }
152              
153             sub _update
154             {
155 0     0     return 1;
156             }
157              
158             sub _width
159             {
160 0     0     my $self = shift;
161 0           $self->{"width"} = 0.5 + (0.6 * length($self->{"name"}));
162 0           return 1;
163             }
164              
165             sub _height
166             {
167 0     0     my $self = shift;
168 0           $self->{"height"} = 2.5;
169 0           return 1;
170             }
171              
172             sub _set_updated
173             {
174 0     0     my $self = shift;
175 0           my $field = shift;
176              
177 0           ${$self->{"_updated"}}{$field} = 1;
  0            
178              
179 0           return 1;
180             }
181              
182             1;
183              
184             ###############################################################################
185              
186             =head1
187              
188             =cut