WiX3/XML/Component.pm untested

filter: Statementstmt 0.0% 0 / 109 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 153 CC 8 SCAR 26.9
CC
8
Cov
0%
BUILDARGS
42.0
as_string
6.0
get_directory_id
6.0
CRAP 14.8
1 package WiX3::XML::Component;
2  
3 use 5.008003;
4  
5 # Must be done before Moose, or it won't get picked up.
6 use metaclass (
7 metaclass => 'Moose::Meta::Class',
8 error_class => 'WiX3::Util::Error',
9 );
10 use Moose 2;
11 use Params::Util qw( _STRING _IDENTIFIER );
12 use WiX3::Types qw( YesNoType ComponentGuidType );
13 use WiX3::XML::TagTypes qw( ComponentChildTag );
14 use MooseX::Types::Moose qw( Str Maybe Int ArrayRef Undef );
15 use WiX3::Util::StrictConstructor;
16  
17 our $VERSION = '0.011';
18  
19 # http://wix.sourceforge.net/manual-wix3/wix_xsd_component.htm
20  
21 with qw(WiX3::XML::Role::TagAllowsChildTags
22 WiX3::XML::Role::GeneratesGUID
23 WiX3::Role::Traceable
24 );
25  
26 ## Environment, File, RegistryKey, RegistryValue, RemoveFolder, Shortcut
27 ## are ComponentChildTags at the moment.
28  
29 has '+child_tags' => ( isa => ArrayRef [ComponentChildTag] );
30  
31 ## Allows lots of children: Choice of elements AppId, Category, Class,
32 ## Condition, CopyFile, CreateFolder, Environment, Extension, File, IniFile,
33 ## Interface, IsolateComponent, ODBCDataSource, ODBCDriver, ODBCTranslator,
34 ## ProgId, Registry, RegistryKey, RegistryValue, RemoveFile, RemoveFolder,
35 ## RemoveRegistryKey, RemoveRegistryValue, ReserveCost, ServiceConfig,
36 ## ServiceConfigFailureActions, ServiceControl, ServiceInstall, Shortcut,
37 ## SymbolPath, TypeLib
38  
39 #####################################################################
40 # Accessors:
41  
42 has id => (
43 is => 'ro',
44 isa => Str,
45 reader => 'get_id',
46 builder => 'id_build',
47 lazy => 1,
48 );
49  
50 has complusflags => (
51 is => 'ro',
52 isa => Maybe [Int],
53 reader => '_get_complusflags',
54 default => undef,
55 );
56  
57 has directory => (
58 is => 'ro',
59 isa => Maybe [Str],
60 reader => '_get_directory',
61 default => undef,
62 );
63  
64 # DisableRegistryReflection requires Windows Installer 4.0
65  
66 has disableregistryreflection => (
67 is => 'ro',
68 isa => YesNoType | Undef,
69 reader => '_get_disableregistryreflection',
70 default => undef,
71 coerce => 1,
72 );
73  
74 has diskid => (
75 is => 'ro',
76 isa => Maybe [Int],
77 reader => '_get_diskid',
78 default => undef,
79 );
80  
81 has feature => (
82 is => 'ro',
83 isa => Maybe [Str],
84 reader => '_get_feature',
85 default => undef,
86 );
87  
88 has guid => (
89 is => 'ro',
90 isa => ComponentGuidType,
91 reader => 'get_guid',
92 lazy => 1,
93 init_arg => undef,
94 builder => 'guid_build',
95 );
96  
97 has keypath => (
98 is => 'ro',
99 isa => YesNoType | Undef,
100 reader => '_get_keypath',
101 default => undef,
102 coerce => 1,
103 );
104  
105 has location => (
106 is => 'ro',
107 isa => Maybe [Str], # Enum: 'local', 'source', 'network'
108 reader => '_get_location',
109 default => undef,
110 );
111  
112 has neveroverwrite => (
113 is => 'ro',
114 isa => YesNoType | Undef,
115 reader => '_get_neveroverwrite',
116 default => undef,
117 coerce => 1,
118 );
119  
120 has path => (
121 is => 'ro',
122 isa => Maybe [Str],
123 reader => 'get_path',
124 default => undef,
125 );
126  
127 has permanent => (
128 is => 'ro',
129 isa => YesNoType | Undef,
130 reader => '_get_permanent',
131 default => undef,
132 coerce => 1,
133 );
134  
135 # Shared requires Windows Installer 4.5
136  
137 has shared => (
138 is => 'ro',
139 isa => YesNoType | Undef,
140 reader => '_get_shared',
141 default => undef,
142 coerce => 1,
143 );
144  
145 has shareddllrefcount => (
146 is => 'ro',
147 isa => YesNoType | Undef,
148 reader => '_get_shareddllrefcount',
149 default => undef,
150 coerce => 1,
151 );
152  
153 has transitive => (
154 is => 'ro',
155 isa => YesNoType | Undef,
156 reader => '_get_transitive',
157 default => undef,
158 coerce => 1,
159 );
160  
161 # UninstallWhenSuperceded requires Windows Installer 4.5
162  
163 has uninstallwhensuperceded => (
164 is => 'ro',
165 isa => YesNoType | Undef,
166 reader => '_get_uninstallwhensuperceded',
167 default => undef,
168 coerce => 1,
169 );
170  
171 has win64 => (
172 is => 'ro',
173 isa => YesNoType | Undef,
174 reader => '_get_win64',
175 default => undef,
176 coerce => 1,
177 );
178  
179 #####################################################################
180 # Methods to implement the Tag role.
181  
182 sub BUILDARGS {
183 my $class = shift;
184 my %args;
185  
186 if ( @_ == 1 && 'HASH' eq ref $_[0] ) {
187 %args = %{ $_[0] };
188 } elsif ( 0 == @_ % 2 ) {
189 %args = @_;
190 } else {
191 WiX3::Exception::Parameter::Odd->throw("$class->new");
192 }
193  
194 if ( defined $args{'guid'} ) {
195  
196 # TODO: Throw exception.
197 }
198  
199 if ( not( defined $args{'id'} or defined $args{'path'} ) ) {
200 WiX3::Exception::Parameter->throw(
201 "Either id or path required in $class->new");
202 }
203  
204 if ( defined $args{id} and not defined _IDENTIFIER("C_$args{id}") ) {
205 print "Invalid ID: $args{id}\n";
206 WiX3::Exception::Parameter::Invalid->throw('id');
207 }
208  
209  
210 return \%args;
211 } ## end sub BUILDARGS
212  
213 sub as_string {
214 my $self = shift;
215  
216 my $children = $self->has_child_tags();
217 my $child_string = $self->as_string_children();
218 my $id = 'C_' . $self->get_id();
219  
220  
221 my $string;
222 $string = '<Component';
223  
224 my @attribute = (
225 [ 'Id' => $id, ],
226 [ 'Guid' => $self->get_guid(), ],
227 [ 'ComPlusFlags' => $self->_get_complusflags(), ],
228 [ 'Directory' => $self->_get_directory(), ],
229 [ 'DisableRegistryReflection' =>
230 $self->_get_disableregistryreflection(),
231 ],
232 [ 'DiskId' => $self->_get_diskid(), ],
233 [ 'Feature' => $self->_get_feature(), ],
234 [ 'Keypath' => $self->_get_keypath(), ],
235 [ 'Location' => $self->_get_location(), ],
236 [ 'NeverOverwrite' => $self->_get_neveroverwrite(), ],
237 [ 'Permanent' => $self->_get_permanent(), ],
238 [ 'Shared' => $self->_get_shared(), ],
239 [ 'SharedDllRefCount' => $self->_get_shareddllrefcount(), ],
240 [ 'Transitive' => $self->_get_transitive(), ],
241 [ 'UninstallWhenSuperceded' =>
242 $self->_get_uninstallwhensuperceded(),
243 ],
244 [ 'Win64' => $self->_get_win64(), ],
245 );
246  
247 my ( $k, $v );
248  
249 foreach my $ref (@attribute) {
250 ( $k, $v ) = @{$ref};
251 $string .= $self->print_attribute( $k, $v );
252 }
253  
254 if ($children) {
255 $string .= qq{>\n$child_string\n</Component>\n};
256 } else {
257 $string .= qq{ />\n};
258 }
259  
260 return $string;
261 } ## end sub as_string
262  
263 sub get_namespace {
264 return q{xmlns='http://schemas.microsoft.com/wix/2006/wi'};
265 }
266  
267 #####################################################################
268 # Other methods.
269  
270 sub get_directory_id {
271 my $self = shift;
272 my $id = $self->get_id();
273  
274 if ( $self->noprefix() ) {
275 return $id;
276 } else {
277 return "D_$id";
278 }
279 }
280  
281 no Moose;
282 __PACKAGE__->meta->make_immutable;
283  
284 1;
285  
286 __END__