Visio/Shape.pm

filter: Statementstmt 28.4% 35 / 123 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 47.8% 11 / 23 Podpod 0.0% 0 / 12 totaltotal 26.1% 46 / 176 CC 11 SCAR 21.8
CC
11
Cov
25%
connect
30.0
get_hyperlink
20.0
new
6.0
CRAP 8.8
↑ Summary Visio.pm »
1 package Visio::Shape;
2  
3  
4  
5  
6  
7 #PLEASE SEE MSPATENTLICENSE
8 # "This product may incorporate intellectual property owned by
9 # Microsoft Corporation. The terms and conditions upon which Microsoft
10 # is licensing such intellectual property may be found at
11 # http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp"
12  
13 # Copyright 2005 Aamer Akhter. All rights reserved.
14  
15 # Redistribution and use in source and binary forms, with or without
16 # modification, are permitted provided that the following conditions are
17 # met:
18  
19 # 1. Redistributions of source code must retain the above copyright
20 # notice, this list of conditions and the following disclaimer.
21  
22 # 2. Redistributions in binary form must reproduce the above copyright
23 # notice, this list of conditions and the following disclaimer in the
24 # documentation and/or other materials provided with the distribution.
25  
26 # THIS SOFTWARE IS PROVIDED BY THE LICENSOR(S) ``AS IS'' AND ANY EXPRESS
27 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 # DISCLAIMED. IN NO EVENT SHALL THE LICENSOR(S) OR OTHER CONTRIBUTORS BE
30 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
33 # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
36 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  
38 # The views and conclusions contained in the software and documentation
39 # are those of the authors and should not be interpreted as representing
40 # official policies, either expressed or implied, of the Licensor(s).
41  
42 # The software may be subject to additional license restrictions
43 # provided by the Licensor(s).
44  
45  
46 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use Log::Log4perl qw(get_logger);
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 1 ▶use Visio::Line;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use Visio::Layout;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Visio::Hyperlink;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 1 $VERSION = sprintf "%d.%03d", q$Revision: 1.9 $ =~ /: (\d+)\.(\d+)/;
60  
61 1 my $log = get_logger('visio.Shape');
62  
63 # Preloaded methods go here.
64  
65 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
66 0 my $class = shift;
67 0 my $ShapesN = shift;
68 0 my $id = shift;
69 0 my $opts = shift;
70 0 my $fromMaster = $$opts{fromMaster};
71 0 my $self = {};
72 0 $self->{pageSelf} = $$opts{pageSelf};
73 0 $self->{ShapesN} = $ShapesN;
74 0 $self->{xmldoc} = $ShapesN->ownerDocument;
75 0 $self->{xmlroot} = $self->{xmldoc}->documentElement;
76 0 $self->{shapeid} = $id;
77 0 bless($self,$class);
78 0 $self->{shapeNode} = $self->{xmldoc}->createElement('Shape');
79 0 $self->{ShapesN}->appendChild($self->{shapeNode});
80 0 ▶ if (defined $fromMaster) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fromMaster) 0 0 0
81 0 $self->{shapeNode}->setAttribute('Master',
82 $fromMaster->get_id()
83 );
84 }
85 0 $self->set_id;
86 0 $log->debug("visio Shape object ($id) created");
87 0 return $self;
88 }
89  
90 0 ▶sub set_id {
Subroutine set_id: not called CC=1 SCAR=6.9
Pod undocumented
91 0 my $self = shift;
92 0 $self->{shapeNode}->setAttribute('ID',$self->{shapeid});
93 }
94  
95 0 ▶sub get_id {
Subroutine get_id: not called CC=1 SCAR=6.9
Pod undocumented
96 0 my $self = shift;
97 0 return $self->{shapeid};
98 }
99  
100  
101  
102 0 ▶sub set_name {
Subroutine set_name: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my $self = shift;
104 0 my $name = shift;
105 0 $self->{shapeNode}->setAttribute('Name',$name);
106 }
107  
108 0 ▶sub get_node {
Subroutine get_node: not called CC=1 SCAR=6.9
Pod undocumented
109 0 my $self = shift;
110 0 return $self->{shapeNode};
111 }
112  
113  
114 0 ▶sub set_text {
Subroutine set_text: not called CC=1 SCAR=6.9
Pod undocumented
115 0 my $self = shift;
116 0 my $text = shift;
117 0 my $opts = shift;
118 my $textN = Visio::generic_create_node($self->{shapeNode},
119 0 'Text'
120 );
121 0 my $textNode = $self->{xmldoc}->createTextNode($text);
122 0 $textN->removeChildNodes();
123 0 $textN->appendChild($textNode);
124 }
125  
126  
127 0 ▶sub get_line {
Subroutine get_line: not called CC=2 SCAR=17.9
Pod undocumented
128 0 my $self = shift;
129 0 ▶ if (defined $self->{Line}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'Line'}) { } 0 0 0
130 } else {
131 $self->{Line} =
132 0 new Visio::Line($self->{shapeNode});
133 }
134 0 return $self->{Line};
135 }
136  
137 0 ▶sub get_hyperlink {
Subroutine get_hyperlink: not called CC=4 SCAR=30.0
Pod undocumented
138 0 my $self = shift;
139 0 my $opts = shift;
140 0 my $hlink;
141 0 ▶ if (defined $self->{maxhyperlinkid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'maxhyperlinkid'}) { } 0 0 0
142 0 $self->{maxhyperlinkid} = $self->{maxhyperlinkid} + 1;
143 } else {
144 0 $self->{maxhyperlinkid} = 1;
145 }
146  
147 $hlink = new Visio::Hyperlink(
148 $self->{shapeNode},
149 $self->{maxhyperlinkid}
150 0 );
151 0 foreach my $key (keys %$opts) {
152 0 ▶ if ($key =~ /^-(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^-(.+)/) { } 0 0 0
153 0 my $prop = $1;
154 0 $hlink->set_property($prop,$$opts{$key});
155 } else {
156  
157 }
158 }
159 0 return $hlink;
160 }
161  
162  
163 0 ▶sub set_LineProperty {
Subroutine set_LineProperty: not called CC=1 SCAR=6.9
Pod undocumented
164 0 my $self = shift;
165 0 my $property = shift;
166 0 my $value = shift;
167 0 my $format = shift;
168 0 $self->get_line()->set_LineProperty($property,$value,$format)
169 }
170  
171 0 ▶sub get_layout {
Subroutine get_layout: not called CC=2 SCAR=17.9
Pod undocumented
172 0 my $self = shift;
173 0 ▶ if (defined $self->{Layout}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'Layout'}) { } 0 0 0
174 } else {
175 $self->{Layout} =
176 0 new Visio::Layout($self->{shapeNode});
177 }
178 0 return $self->{Layout};
179 }
180  
181 0 ▶sub set_LayoutProperty {
Subroutine set_LayoutProperty: not called CC=1 SCAR=6.9
Pod undocumented
182 0 my $self = shift;
183 0 my $property = shift;
184 0 my $value = shift;
185 0 my $format = shift;
186 0 $self->get_layout()->set_LayoutProperty($property,$value,$format)
187 }
188  
189 0 ▶sub connect {
Subroutine connect: not called CC=5 SCAR=34.0
Pod undocumented
190 0 my $self = shift;
191 0 my $begin = shift;
192 0 my $end = shift;
193 0 ▶ if (!defined $begin) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $begin) 0 0 0
194 0 $log->error('$begin not defined in connect');
195 0 return -1;
196 }
197 0 ▶ if ($begin->isa('Visio::Shape')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($begin->isa("Visio::Shape")) 0 0 0
198 0 $begin = $begin->get_id;
199 }
200 0 ▶ if (!defined $end) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $end) 0 0 0
201 0 $log->error('$end not defined in connect');
202 0 return -1
203 }
204 0 ▶ if ($end->isa('Visio::Shape')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end->isa("Visio::Shape")) 0 0 0
205 0 $end = $end->get_id;
206 }
207  
208 0 my $connectN1 = $self->{pageSelf}->create_connect();
209 0 $connectN1->setAttribute('FromSheet',$self->{shapeid});
210 0 $connectN1->setAttribute('FromCell','BeginX');
211 0 $connectN1->setAttribute('ToSheet',$begin);
212 0 $connectN1->setAttribute('ToCell','PinX');
213  
214 0 my $connectN2 = $self->{pageSelf}->create_connect();
215 0 $connectN2->setAttribute('FromSheet',$self->{shapeid});
216 0 $connectN2->setAttribute('FromCell','EndX');
217 0 $connectN2->setAttribute('ToSheet',$end);
218 0 $connectN2->setAttribute('ToCell','PinX');
219 }
220  
221 1 1;
222 __END__
↑ Summary Visio.pm »