blib/lib/FreeBSD/Src.pm

filter: Statementstmt 7.4% 8 / 108 Branchbran 0.0% 0 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 16.6% 2 / 12 Podpod 100% 10 / 10 totaltotal 11.9% 20 / 168 CC 20 SCAR 35.2
CC
20
Cov
5%
new
90.0
makeBuildKernel
20.0
makeBuildWorld
12.0
CRAP 33.7
↑ Summary
1 package FreeBSD::Src;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 FreeBSD::Src - A object oriented interface to building FreeBSD from source.
9  
10 =head1 VERSION
11  
12 Version 2.0.0
13  
14 =cut
15  
16 2 our $VERSION = '2.0.0';
17  
18  
19 =head1 SYNOPSIS
20  
21 use FreeBSD::Src;
22  
23 #creates a new FreeBSD::Src object and build stuff in /tm[/obj and a kernel config
24 #named whatever.
25 my $src=FreeBSD::Src->new({obj=>"/tmp/obj", kernel=>"whatever"});
26 if($src->error){
27 warn('Error: '.$src->error);
28 }
29  
30 #builds and installs the kernel and world
31 $src->makeBuildKernel;
32 if($src->error){
33 warn('Error: '.$src->error);
34 }
35 $src->makeInstallKernel;
36 if($src->error){
37 warn('Error: '.$src->error);
38 }
39 $src->makeBuildWorld;
40 if($src->error){
41 warn('Error: '.$src->error);
42 }
43 $src->makeInstallWorld;
44 if($src->error){
45 warn('Error: '.$src->error);
46 }
47  
48 =head1 METHODS
49  
50 =head2 new
51  
52 This creates the object that will be used. It takes arguement, which is a hash
53 that contains various options that will be used.
54  
55 =head3 src
56  
57 This key contains the path to which contains the FreeBSD source. This this does
58 not exist, it results in a permanent error.
59  
60 The default is '/usr/src' if it is not defined.
61  
62 =head3 obj
63  
64 This contains the path to the directory that will contain objects created by the compilation.
65  
66 If not defined, the enviromental variable "MAKEOBJDIR" will be left
67 as it is.
68  
69 =head3 kernel
70  
71 This is the kernel config that will be build.
72  
73 If this is defined, it is left up to make to figure out which should be used. For
74 more information, please see the man page make.conf(5).
75  
76 =head3 makeconf
77  
78 This is the make.conf file to use for the build.
79  
80 my $src=FreeBSD::Src->new({obj=>"/tmp/obj", kernel=>"whatever"});
81 if($src->error){
82 warn('Error: '.$src->error);
83 }
84  
85 =cut
86  
87 0 ▶sub new{
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
88 0 my %args;
89 0 ▶ if (defined( $_[1] )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
90 0 %args=%{$_[1]};
91 }
92  
93 #create the object that will be passed around
94 0 my $self = {conf=>{}, error=>undef, returnedInt=>undef,
95 returned=>undef, permanentError=>undef};
96 0 bless $self;
97  
98 #this will be appended to the end of make
99 0 $self->{conf}{makeappend}="";
100  
101 #gets what to use as the src directory
102 0 ▶ if(!defined($args{src})){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{'src'}) { } 0 0 0
103 0 $self->{conf}{src}="/usr/src";
104 }else{
105 0 $self->{conf}{src}=$args{src};
106 }
107  
108 #gets what to use for the destination directory
109 0 ▶ if (defined($args{destdir})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"destdir"}) 0 0 0
110 0 $self->{conf}{destdir}=$args{destdir};
111 $self->{conf}{makeappend}=$self->{conf}{makeappend}.
112 0 " DESTDIR='".$self->{conf}{destdir}."'";
113 }
114  
115 #figures out what to use for obj dir
116 0 ▶ if(!defined($args{obj})){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{'obj'}) { } 0 0 0
117 0 $self->{conf}{obj}=undef;
118 }else{
119 0 $self->{conf}{obj}=$args{obj};
120 }
121 #sets the obj dir
122 0 ▶ if (defined($self->{conf}{obj})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"conf"}{"obj"}) 0 0 0
123 0 $ENV{MAKEOBJDIR}=$self->{conf}{obj};
124 }
125  
126 0 ▶ if(!defined($args{kernel})){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{'kernel'}) { } 0 0 0
127 0 $self->{conf}{kernel}=undef;
128 }else{
129 0 $self->{conf}{kernel}=$args{kernel};
130 }
131  
132 #sets the make.conf
133 0 ▶ if(!defined($args{makeconf})){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{'makeconf'}) { } 0 0 0
134 0 $self->{conf}{makeconf}="/etc/make.conf";
135 }else{
136 0 $self->{conf}{makeconf}=$args{makeconf};
137 }
138  
139 0 ▶ if(!-e $self->{conf}{src}){
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $self->{"conf"}{"src"}) 0 0 0
140 0 warn('FreeBSD::Src error:0: The directory source directory, '.$self->{conf}{src}.', does not exist.');
141 0 $self->{permanentError}="5";
142 0 $self->{error}="5";
143 }
144  
145 0 return $self;
146 }
147  
148 =head2 makeBuildWorld
149  
150 Builds the world.
151  
152 The return is a perl boolean value.
153  
154 The returned integer from make can be found using the exitint method.
155  
156 $src->makeBuildWorld;
157 if($src->error){
158 warn('Error: '.$src->error);
159 }
160  
161 =cut
162  
163 0 ▶sub makeBuildWorld{
Subroutine makeBuildWorld: not called CC=3 SCAR=24.8
Pod documented
164 0 my ($self)= @_;
165  
166 0 ▶ if(defined($self->{permanentError})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"permanentError"}) 0 0 0
167 0 $self->{error}=$self->{permanentError};
168 0 return undef;
169 }
170  
171 0 $self->errorBlank();
172  
173 0 chdir($self->{conf}{src});
174  
175 0 $self->{returned}=`make buildworld __MAKE_CONF=$self->{conf}{makeconf} $self->{conf}{makeappend}`;
176 0 $self->{returnedInt}=$?;
177 0 ▶ if (!$self->{returnedInt} == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (!$self->{"returnedInt"} == 0) 0 0 0
178 0 $self->{error}=1;
179 0 return undef;
180 }
181 0 return 1;
182 }
183  
184 =head2 makeInstallWorld
185  
186 Installs the world.
187  
188 The return is a perl boolean value.
189  
190 The returned integer from make can be found using the exitint method.
191  
192 $src->makeInstallWorld;
193 if($src->error){
194 warn('Error: '.$src->error);
195 }
196  
197 =cut
198  
199 0 ▶sub makeInstallWorld{
Subroutine makeInstallWorld: not called CC=3 SCAR=24.8
Pod documented
200 0 my ($self)= @_;
201  
202 0 ▶ if(defined($self->{permanentError})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"permanentError"}) 0 0 0
203 0 $self->{error}=$self->{permanentError};
204 0 return undef;
205 }
206  
207 0 $self->errorBlank();
208  
209 0 chdir($self->{conf}{src});
210  
211 0 $self->{returned}=`make installworld __MAKE_CONF=$self->{conf}{makeconf} $self->{conf}{makeappend}`;
212 0 $self->{returnedInt}=$?;
213 0 ▶ if (!$self->{returnedInt} == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (!$self->{"returnedInt"} == 0) 0 0 0
214 0 $self->{error}=2;
215 0 return undef;
216 }
217 0 return 1;
218 }
219  
220 =head2 makeBuildKernel
221  
222 Builds the kernel
223  
224 The return is a perl boolean value.
225  
226 The returned integer from make can be found using the exitinit method.
227  
228 $src->makeBuildKernel;
229 if($src->error){
230 warn('Error: '.$src->error);
231 }
232  
233 =cut
234  
235 0 ▶sub makeBuildKernel{
Subroutine makeBuildKernel: not called CC=4 SCAR=30.0
Pod documented
236 0 my ($self)= @_;
237  
238 0 ▶ if(defined($self->{permanentError})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"permanentError"}) 0 0 0
239 0 $self->{error}=$self->{permanentError};
240 0 return undef;
241 }
242  
243 0 $self->errorBlank();
244  
245 0 chdir($self->{conf}{src});
246  
247 0 my $makecommand='make buildkernel __MAKE_CONF='.$self->{conf}{makeconf};
248 0 ▶ if (defined($self->{conf}{kernel})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"conf"}{"kernel"}) 0 0 0
249 0 $makecommand=$makecommand.' KERNCONF='.$self->{conf}{kernel};
250 }
251 0 $makecommand=$makecommand.' '.$self->{conf}{makeappend};
252  
253 0 $self->{returned}=`$makecommand`;
254 0 $self->{returnedInt}=$?;
255 0 ▶ if (!$self->{returnedInt} == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (!$self->{"returnedInt"} == 0) 0 0 0
256 0 $self->{error}=3;
257 0 return undef;
258 }
259 0 return 1;
260 }
261  
262 =head2 makeInstallKernel
263  
264 Install the kernel.
265  
266 The return is a perl boolean value.
267  
268 The returned integer from make can be reached in exitint method.
269  
270 $src->makeInstallKernel;
271 if($src->error){
272 warn('Error: '.$src->error);
273 }
274  
275 =cut
276  
277 0 ▶sub makeInstallKernel{
Subroutine makeInstallKernel: not called CC=3 SCAR=24.8
Pod documented
278 0 my ($self)= @_;
279  
280 0 ▶ if(defined($self->{permanentError})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"permanentError"}) 0 0 0
281 0 $self->{error}=$self->{permanentError};
282 0 return undef;
283 }
284  
285 0 $self->errorBlank();
286  
287 0 chdir($self->{conf}{src});
288  
289 0 $self->{returned}=`make installkernel`;
290 0 $self->{returnedInt}=$?;
291 0 ▶ if (!$self->{returnedInt} == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (!$self->{"returnedInt"} == 0) 0 0 0
292 0 $self->{error}=4;
293 0 return undef;
294 }
295 0 return 1;
296 }
297  
298 =head2 makeClean
299  
300 This cleans the build enviroment.
301  
302 The return is a perl boolean value.
303  
304 The returned integer from make can be found using the exitinit method.
305  
306 $src->makeClean;
307 if($src->error){
308 warn('Error: '.$src->error);
309 }
310  
311 =cut
312  
313 0 ▶sub makeClean{
Subroutine makeClean: not called CC=3 SCAR=24.8
Pod documented
314 0 my ($self)= @_;
315  
316 0 ▶ if(defined($self->{permanentError})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"permanentError"}) 0 0 0
317 0 $self->{error}=$self->{permanentError};
318 0 return undef;
319 }
320  
321 0 $self->errorBlank();
322  
323 0 chdir($self->{conf}{src});
324  
325 0 $self->{returned}=`make clean`;
326 0 $self->{returnedInt}=$?;
327 0 ▶ if (!$self->{returnedInt} == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (!$self->{"returnedInt"} == 0) 0 0 0
328 0 $self->{error}=3;
329 0 return undef;
330 }
331 0 return 1;
332 }
333  
334  
335 =head2 output
336  
337 This gets the stdout from make from the previously called method.
338  
339 my $output=$src->output;
340  
341 =cut
342  
343 0 ▶sub output{
Subroutine output: not called CC=1 SCAR=6.9
Pod documented
344 0 my $self=$_[0];
345  
346 0 return $self->{returned};
347 }
348  
349 =head1 ERROR RELATED METHODS
350  
351 =head2 error
352  
353 This returns the current error code, if any.
354  
355 my $error=$src->error;
356 if($error){
357 warn('Error Code: '.$error);
358 }
359  
360 =cut
361  
362 0 ▶sub error{
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
363 0 return $_[0]->{error};
364 }
365  
366 =head2 exitint
367  
368 This is exit int from the make of the last called method.
369  
370  
371  
372 =cut
373  
374 0 ▶sub exitint{
Subroutine exitint: not called CC=1 SCAR=6.9
Pod documented
375 0 return $_[0]->{returnedInt};
376 }
377  
378 =head2 errorBlank
379  
380 This is a internal function and should not be called.
381  
382 =cut
383  
384 #blanks the error flags
385 0 ▶sub errorBlank{
Subroutine errorBlank: not called CC=1 SCAR=6.9
Pod documented
386 0 my $self=$_[0];
387  
388 0 $self->{error}=undef;
389  
390 0 return 1;
391 }
392  
393 =head1 ERROR CODES
394  
395 =head2 0
396  
397 The source directory does not exist.
398  
399 =head2 1
400  
401 'make buildworld' failed.
402  
403 =head2 2
404  
405 'make installdworld' failed.
406  
407 =head2 3
408  
409 'make buildkernel KERNCONF=<kernel>' failed.
410  
411 =head2 4
412  
413 'make installkernel KERNCONF=<kernel>' failed.
414  
415 =head2 5
416  
417 The source directory does not exist.
418  
419 =head1 AUTHOR
420  
421 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
422  
423 =head1 BUGS
424  
425 Please report any bugs or feature requests to C<bug-freebsd-src at rt.cpan.org>, or through
426 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FreeBSD-Src>. I will be notified, and then you'll
427 automatically be notified of progress on your bug as I make changes.
428  
429 =head1 SUPPORT
430  
431 You can find documentation for this module with the perldoc command.
432  
433 perldoc FreeBSD::Src
434  
435  
436 You can also look for information at:
437  
438 =over 4
439  
440 =item * RT: CPAN's request tracker
441  
442 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=FreeBSD-Src>
443  
444 =item * AnnoCPAN: Annotated CPAN documentation
445  
446 L<http://annocpan.org/dist/FreeBSD-Src>
447  
448 =item * CPAN Ratings
449  
450 L<http://cpanratings.perl.org/d/FreeBSD-Src>
451  
452 =item * Search CPAN
453  
454 L<http://search.cpan.org/dist/FreeBSD-Src>
455  
456 =back
457  
458  
459 =head1 ACKNOWLEDGEMENTS
460  
461  
462 =head1 COPYRIGHT & LICENSE
463  
464 Copyright 2011 Zane C. Bowers, all rights reserved.
465  
466 This program is free software; you can redistribute it and/or modify it
467 under the same terms as Perl itself.
468  
469  
470 =cut
471  
472 2 1; # End of FreeBSD::Src
↑ Summary