StanzaFile/Lilo.pm

filter: Statementstmt 31.5% 12 / 38 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 30.5% 18 / 59 CC 8 SCAR 24.8
CC
8
Cov
24%
stanzaAsString
20.0
isBeginning
12.0
isValue
12.0
CRAP 11.9
« Stanza.pm ↑ Summary StanzaFile/Grub.pm »
1 #
2 # Revision History:
3 # 27-Nov-2002 Dick Munroe (munroe@csworks.com)
4 # Initial Version Created.
5 #
6 # 22-Dec-2002 Dick Munroe (munroe@csworks.com)
7 # Add documentation on use and overridden methods.
8 #
9 # 17-May-2003 Dick Munroe (munroe@csworks.com)
10 # Fix things so that package variables can't leak and clobber
11 # other packages.
12 #
13 # 20-May-2003 Dick Munroe (munroe@csworks.com)
14 # Make the test harness happy.
15 #
16  
17 package StanzaFile::Lilo ;
18  
19 1 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use vars qw($VERSION @ISA) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use StanzaFile::Grub ;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 our $VERSION = "1.02" ;
25  
26 1 our @ISA = qw(StanzaFile::Grub) ;
27  
28 sub isBeginning
29 0 ▶{
Subroutine isBeginning: not called CC=3 SCAR=24.8
Pod documented
30 0 ▶ die "Too few arguments passed to StanzaFile::Lilo::isBeginning" if (scalar(@_) < 2) ;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 2 0 0 0
31  
32 0 my ($theObject, $theLine) = @_ ;
33  
34 0 ▶ if ($theLine =~ m/^image\s*=\s*(.*)/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($theLine =~ /^image\s*=\s*(.*)/i) 0 0 0
35 {
36 0 my $theName = $1 ;
37  
38 0 $theName =~ s/(.*?)\s+$/$1/ ;
39 0 $theName =~ s/\s{2,}/ /g ;
40  
41 0 return $theName ;
42 } ;
43  
44 0 return undef ;
45 } ;
46  
47 sub isValue
48 0 ▶{
Subroutine isValue: not called CC=3 SCAR=24.8
Pod documented
49 0 my ($theObject, $theLine) = @_ ;
50  
51 0 ▶ if ($theLine =~ m/^\s*(.*?)\s*=\s*(.*)/)
Branch: 2 branches
BranchTrueFalseTotal
if ($theLine =~ /^\s*(.*?)\s*=\s*(.*)/) { } 0 0 0
elsif ($theLine =~ /^\s*(.*?)(\s|$)/) { } 0 0 0
52 {
53 0 return ($1, $2) ;
54 }
55 elsif ($theLine =~ m/^\s*(.*?)(\s|$)/)
56 {
57 0 return ($1, undef) ;
58 }
59 else
60 {
61 0 return undef ;
62 } ;
63 } ;
64  
65 sub stanzaAsString
66 0 ▶{
Subroutine stanzaAsString: not called CC=4 SCAR=30.0
Pod documented
67 0 my ($theObject, $theStanza) = @_ ;
68  
69 0 my $theString = "image=" . $theStanza->name() . "\n" ;
70  
71 0 my $theLength ;
72  
73 0 ▶ map { $theLength = length($_) if (length($_) > $theLength) ; } $theStanza->order() ;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > $theLength 0 0 0
74  
75 0 $theLength++ ;
76  
77 0 $theLength = "%-" . $theLength . "s" ;
78  
79 0 foreach ($theStanza->order())
80 {
81 0 $theString = $theString . "\t" . sprintf($theLength,$_) ;
82 0 ▶ if (defined($theStanza->item($_)))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $theStanza->item($_)) 0 0 0
83 {
84 0 $theString = $theString . "= " . $theStanza->item($_) ;
85 } ;
86 0 $theString = $theString . "\n" ;
87 } ;
88  
89 0 return $theString ;
90 } ;
91  
92 1 1;
93  
94 =pod
95  
96 =head1 NAME
97  
98 StanzaFile::Lilo - read, parse, and write Linux Loader configuration
99 files.
100  
101 =head1 SYNOPSIS
102
103 There are no interface changes between this and the parent
104 class, StanzaFile::Grub. This is included, partly, as an example
105 of the ease with which additional different stanza file
106 formats can be supported using the StanzaFile class and,
107 mostly, because I used the StanzaFile::Lilo class in a kernel
108 build and installation management package I wrote (check it
109 out, L<http://www.sourceforge.net/projects/kif/>).
110  
111 =head1 DESCRIPTION
112  
113 The lilo configuration file format differs in a couple of ways
114 from the grug.conf format. Both are in stanzas, but the stanza
115 beginning and the format of the lines in the file are slightly
116 different.
117  
118 These differences are accommodated by overriding three of the
119 methods defined in StanzaFile::Grub. These are:
120  
121 =item $theObject->isBeginning($line)
122  
123 A predicate which tests the line to see if it is the beginning of
124 a new stanza. If it is, the value of the predicate is the name of
125 the new stanza. Otherwise the value of the predicate is undefined.
126  
127 =item $theObject->isValue($line)
128  
129 A predicate which tests the line to see if it contains a name/value
130 pair and returns that pair as the value of the prediate. Otherwise
131 it returns and undefined.
132  
133 =item $theObject->stanzaAsString()
134  
135 Produce a string suitable for printing that represents a lilo
136 configuration file stanza other than the header.
137  
138 =head1 EXAMPLES
139  
140 =head1 BUGS
141  
142 =head1 WARNINGS
143  
144 No comments or whitespace are preserved in the configuration file
145 when it is read and/or written.
146  
147 =head1 AUTHOR
148  
149 Dick Munroe (munroe@csworks). I'm looking for work. If you hear
150 of anything that might be of interest to a VERY senior engineer/architect
151 drop me a note. See
152 http://www.acornsw.com/resume/dick.html for details.
153  
154 =head1 SEE ALSO
155  
156 =cut
157  
« Stanza.pm ↑ Summary StanzaFile/Grub.pm »