File Coverage

blib/lib/StanzaFile/Lilo.pm
Criterion Covered Total %
statement 9 35 25.7
branch 0 12 0.0
condition n/a
subroutine 3 6 50.0
pod 3 3 100.0
total 15 56 26.7


line stmt bran cond sub pod time code
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     1   524 use strict ;
  1         2  
  1         39  
20 1     1   5 use vars qw($VERSION @ISA) ;
  1         2  
  1         54  
21              
22 1     1   5 use StanzaFile::Grub ;
  1         2  
  1         442  
23              
24             our $VERSION = "1.02" ;
25              
26             our @ISA = qw(StanzaFile::Grub) ;
27              
28             sub isBeginning
29             {
30 0 0   0 1   die "Too few arguments passed to StanzaFile::Lilo::isBeginning" if (scalar(@_) < 2) ;
31              
32 0           my ($theObject, $theLine) = @_ ;
33              
34 0 0         if ($theLine =~ m/^image\s*=\s*(.*)/i)
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             {
49 0     0 1   my ($theObject, $theLine) = @_ ;
50              
51 0 0         if ($theLine =~ m/^\s*(.*?)\s*=\s*(.*)/)
    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             {
67 0     0 1   my ($theObject, $theStanza) = @_ ;
68              
69 0           my $theString = "image=" . $theStanza->name() . "\n" ;
70              
71 0           my $theLength ;
72              
73 0 0         map { $theLength = length($_) if (length($_) > $theLength) ; } $theStanza->order() ;
  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 0         if (defined($theStanza->item($_)))
83             {
84 0           $theString = $theString . "= " . $theStanza->item($_) ;
85             } ;
86 0           $theString = $theString . "\n" ;
87             } ;
88              
89 0           return $theString ;
90             } ;
91              
92             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).
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