StanzaFile/Grub.pm

filter: Statementstmt 27.9% 12 / 43 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 100% 5 / 5 totaltotal 30.3% 20 / 66 CC 7 SCAR 21.1
CC
7
Cov
23%
isBeginning
12.0
isValue
12.0
stanzaAsString
12.0
CRAP 8.2
« StanzaFile/Lilo.pm ↑ Summary
1 package StanzaFile::Grub ;
2  
3 #
4 # Revision History:
5 #
6 # 21-Dec-2002 Dick Munroe (munroe@csworks.com)
7 # Add documentation detailing the 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 1 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use vars qw($VERSION @ISA) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use StanzaFile ;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our $VERSION = "1.02" ;
23  
24 1 our @ISA = qw(StanzaFile) ;
25  
26 sub addHeader
27 0 ▶{
Subroutine addHeader: not called CC=1 SCAR=6.9
Pod documented
28 0 my ($theObject, $theLHS, $theRHS) = @_ ;
29  
30 0 $theObject->{'header'}->add($theLHS, $theRHS) ;
31  
32 0 return $theObject ;
33 } ;
34  
35 sub isBeginning
36 0 ▶{
Subroutine isBeginning: not called CC=3 SCAR=24.8
Pod documented
37 0 ▶ die "Too few arguments passed to StanzaFile::Grub::isBeginning" if (scalar(@_) < 2) ;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 2 0 0 0
38  
39 0 my ($theObject, $theLine) = @_ ;
40  
41 0 ▶ if ($theLine =~ m/^title\s+(.*)/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($theLine =~ /^title\s+(.*)/i) 0 0 0
42 {
43 0 my $theName = $1 ;
44  
45 0 $theName =~ s/(.*?)\s+$/$1/ ;
46 0 $theName =~ s/\s{2,}/ /g ;
47  
48 0 return $theName ;
49 } ;
50  
51 0 return undef ;
52 } ;
53  
54 sub isValue
55 0 ▶{
Subroutine isValue: not called CC=3 SCAR=24.8
Pod documented
56 0 my ($theObject, $theLine) = @_ ;
57  
58 #
59 # The grub.conf file format consists of two distinct types of data.
60 # The first is global configuration data and appears before the first
61 # stanza (stanzaFlag in the object will be false when this data is
62 # valid and required. After that, there are image sections containing
63 # menu commands and those have a substantially different format.
64 #
65  
66 0 ▶ if ($theObject->{'stanzaFlag'})
Branch: 1 branch
BranchTrueFalseTotal
if ($theObject->{'stanzaFlag'}) { } 0 0 0
67 {
68 #
69 # If we really wanted to be anal, we could check for all the possible
70 # keywords that could be in grub stanzas. I don't really think there
71 # is any reason to do that.
72 #
73  
74 0 ▶ if ($theLine =~ m/^\s*(\w+)\s+(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($theLine =~ /^\s*(\w+)\s+(.*)/) 0 0 0
75 {
76 0 return ($1, $2)
77 } ;
78  
79 0 return undef ;
80 }
81 else
82 {
83 0 return $theObject->SUPER::isValue($theLine) ;
84 } ;
85 } ;
86  
87 sub headerAsString
88 0 ▶{
Subroutine headerAsString: not called CC=1 SCAR=6.9
Pod documented
89 0 my $theObject = shift ;
90  
91 0 my $theString = $theObject->SUPER::stanzaAsString($theObject->header()) ;
92  
93 0 $theString =~ s/.*?\n// ;
94  
95 0 return $theString ;
96 } ;
97  
98 sub stanzaAsString
99 0 ▶{
Subroutine stanzaAsString: not called CC=3 SCAR=24.8
Pod documented
100 0 my ($theObject, $theStanza) = @_ ;
101  
102 0 my $theString = "title\t" . $theStanza->name() . "\n" ;
103  
104 0 my $theLength ;
105  
106 0 ▶ map { $theLength = length($_) if (length($_) > $theLength) ; } $theStanza->order() ;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > $theLength 0 0 0
107  
108 0 $theLength++ ;
109  
110 0 $theLength = "%-" . $theLength . "s" ;
111  
112 0 foreach ($theStanza->order())
113 {
114 0 $theString = $theString . "\t" . sprintf($theLength,$_) . $theStanza->item($_) . "\n" ;
115 } ;
116  
117 0 return $theString ;
118 } ;
119  
120 1 1;
121  
122 =pod
123  
124 =head1 NAME
125  
126 StanzaFile::Grub - read, parse, and write Grand Unified Bootloader configuration
127 files.
128  
129 =head1 SYNOPSIS
130
131 There are no interface changes between this and the parent
132 class, StanzaFile. This is included, partly, as an example
133 of the ease with which additional different stanza file
134 formats can be supported using the StanzaFile class and,
135 mostly, because I used the StanzaFile::Grub class in a kernel
136 build and installation management package I wrote (check it
137 out, kif at sourceforge.net).
138  
139 =head1 DESCRIPTION
140  
141 The grub configuration file format differs in a couple of ways
142 from the WINDOWS.INI format. It has a "global" section that
143 appears before any of the stanzas actually start. This global
144 section is stored in a dummy stanza accessable via the header
145 method defined in StanzaFile.
146  
147 The format of entries in the global section also differs from
148 entries in the stanzas.
149  
150 All this is dealt with by overriding 5 methods.
151  
152 =over 4
153  
154 =item $theObject->addHeader($leftHandSide, $rightHandSide)
155  
156 addHeader puts a new global header item into the Grub StanzaFile
157 object. The value of the new header item is the value of the
158 $rightHandSide variable and is optional for those header items
159 without values.
160  
161 =item $theObject->headerAsString()
162  
163 Produce a string suitable for printing that represents the contents
164 of the header portion of the Grub stanza file object.
165  
166 =item $theObject->isBeginning($line)
167  
168 A predicate which tests the line to see if it is the beginning of
169 a new stanza. If it is, the value of the predicate is the name of
170 the new stanza. Otherwise the value of the predicate is undefined.
171  
172 =item $theObject->isValue($line)
173  
174 A predicate which tests the line to see if it contains a name/value
175 pair and returns that pair as the value of the prediate. Otherwise
176 it returns and undefined.
177  
178 =item $theObject->stanzaAsString()
179  
180 Produce a string suitable for printing that represents a Grub file
181 stanza other than the header.
182  
183 =back
184  
185 =head1 EXAMPLES
186  
187 =head1 BUGS
188  
189 None known.
190  
191 =head1 WARNINGS
192  
193 No comments or whitespace are preserved in the configuration file
194 when it is read and/or written.
195  
196 =head1 AUTHOR
197  
198 Dick Munroe (munroe@csworks). I'm looking for work. If you hear
199 of anything that might be of interest to a VERY senior engineer/architect
200 drop me a note. See
201 L<http://www.acornsw.com/resume/dick.html> for details.
202  
203 =head1 SEE ALSO
204  
205 The Kernel Installation Facility uses these classes extensively. For more
206 details see L<http://sourceforge.net/projects/kif/>
207  
208 =cut
209  
« StanzaFile/Lilo.pm ↑ Summary