File Coverage

lib/DPKG/Log/Entry.pm
Criterion Covered Total %
statement 55 79 69.6
branch 10 28 35.7
condition 0 3 0.0
subroutine 16 18 88.8
pod 13 13 100.0
total 94 141 66.6


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             DPKG::Log::Entry - Describe a log entry in a dpkg.log
4              
5             =head1 VERSION
6              
7             version 1.20
8              
9             =head1 SYNOPSIS
10              
11             use DPKG::Log::Entry;
12              
13             $dpkg_log_entry = DPKG::Log::Entry->new( line => $line, $lineno => 1)
14              
15             $dpkg_log_entry->timestamp($dt);
16              
17             $dpkg_log_entry->associated_package("foo");
18              
19              
20             =head1 DESCRIPTION
21              
22             This module is used to describe one line in a dpkg log
23             by parameterizing every line into generic parameters like
24              
25             =over 3
26              
27             =item * Type of log entry (startup-, status-, action-lines)
28              
29             =item * Timestamp
30              
31             =item * Subject of log entry (e.g. package, packages or archives)
32              
33             =item * Package name (if log entry refers to a package subject)
34              
35             =back
36              
37             and so on.
38              
39             The various parameters are described below together with
40             the various methods to access or modify them.
41              
42             =head1 METHODS
43              
44              
45             =over 4
46              
47             =cut
48             package DPKG::Log::Entry;
49             BEGIN {
50 6     6   115 $DPKG::Log::Entry::VERSION = '1.20';
51             }
52              
53 6     6   32 use strict;
  6         10  
  6         168  
54 6     6   30 use warnings;
  6         9  
  6         160  
55 6     6   10080 use overload ( '""' => 'line' );
  6         12715  
  6         36  
56              
57             require Exporter;
58             our @ISA = qw(Exporter);
59             our @EXPORT = qw( $valid_types $valid_actions );
60              
61             our $valid_types = {
62             status => 1,
63             action => 1,
64             startup => 1,
65             conffile_action => 1
66            
67             };
68              
69             our $valid_actions = {
70             'install' => 1,
71             'configure' => 1,
72             'trigproc' => 1,
73             'upgrade' => 1,
74             'remove' => 1,
75             'purge' => 1,
76             };
77              
78 6     6   6534 use Params::Validate qw(:all);
  6         67081  
  6         6791  
79              
80             =item $dpkg_log_entry = PACKAGE->new( 'line' => $line, 'lineno' => $lineno )
81              
82             Returns a new DPKG::Log::Entry object.
83             The arguments B and B are mandatore. They store the complete line
84             as stored in the log and the line number.
85              
86             Additionally its possible to specify every attribute the object can store,
87             as 'key' => 'value' pairs.
88              
89             =back
90              
91             =cut
92             sub new {
93 4356     4356 1 113400 my $package = shift;
94 4356 100       8101 $package = ref($package) if ref($package);
95              
96 4356         159833 my %params = validate(
97             @_, {
98             'line' => { 'type' => SCALAR },
99             'lineno' => { 'type' => SCALAR },
100             'timestamp' => '',
101             'associated_package' => '',
102             'action' => '',
103             'status' => '',
104             'subject' => '',
105             'type' => '',
106             'installed_version' => '',
107             'available_version' => '',
108             'decision' => '',
109             'conffile' => '',
110             }
111             );
112 4356         54709 my $self = {
113             %params
114             };
115 4356         11441 bless($self, $package);
116 4356         20045 return $self;
117             }
118              
119             =head1 ATTRIBUTES
120              
121             =over 4
122              
123             =item $dpkg_log_entry->line() / line
124              
125             Return the full log line. This attribute is set on object initialization.
126              
127             =cut
128             sub line {
129 9     9 1 267 my $self = shift;
130 9         43 return $self->{line};
131             }
132              
133             =item $dpkg_log_entry->lineno() / lineno
134              
135             Return the line number of this entry. This attribute is set on object initialization.
136              
137             =cut
138             sub lineno {
139 6     6 1 189 my $self = shift;
140 6         194 return $self->{lineno};
141             }
142              
143             =item $dpkg_log_entry->timestamp() / timestamp
144              
145             Get or set the timestamp of this object. Should be a DateTime object.
146              
147             =cut
148             sub timestamp {
149 3405     3405 1 4518 my ($self, $timestamp) = @_;
150              
151 3405 50       4923 if ($timestamp) {
152 0 0 0     0 if ((not ref($timestamp)) or (ref($timestamp) ne "DateTime")) {
153 0         0 croak("timestamp has to be a DateTime object");
154             }
155 0         0 $self->{timestamp} = $timestamp;
156             } else {
157 3405         5473 $timestamp = $self->{timestamp};
158             }
159 3405         11719 return $timestamp;
160             }
161              
162             =item $dpkg_log_entry->type() / type
163              
164             Get or set the type of this entry. Specifies weither this is a startup,
165             status or action line.
166              
167             =cut
168             sub type {
169 7     7 1 20 my ($self, $type) = @_;
170              
171 7 50       20 if ($type) {
172 0 0       0 if (not defined($valid_types->{$type})) {
173 0         0 croak("$type is not a valid type. has to be one of ".join(",", keys %{$valid_types}));
  0         0  
174             }
175 0         0 $self->{type} = $type;
176             } else {
177 7         18 $type = $self->{type}
178             }
179 7         47 return $type;
180             }
181              
182             =item $dpkg_log_entry->associated_package() / associated_package
183              
184             Get or set the associated_package of this entry. This is for lines that are associated to a certain
185             package like in action or status lines. Its usually unset for startup and status lines.
186              
187             =cut
188             sub associated_package {
189 5     5 1 15 my ($self, $associated_package) = @_;
190              
191 5 50       15 if ($associated_package) {
192 0         0 $self->{associated_package} = $associated_package;
193             } else {
194 5         12 $associated_package = $self->{associated_package};
195             }
196 5         34 return $associated_package;
197             }
198              
199             =item $dpkg_log_entry->action() / action
200              
201             Get or set the action of this entry. This is for lines that have a certain action,
202             like in startup-lines (unpack, configure) or action lines (install, remove).
203             It is usally unset for status lines.
204              
205             =cut
206             sub action {
207 7     7 1 22 my ($self, $action) = @_;
208              
209 7 50       18 if ($action) {
210 0 0       0 if (not defined($valid_actions->{$action})) {
211 0         0 croak("$action is not a valid action. has to be one of ".join(",", keys %{$valid_actions}));
  0         0  
212             }
213 0         0 $self->{action} = $action;
214             } else {
215 7         20 $action = $self->{action};
216             }
217 7         53 return $action;
218             }
219              
220             =item $dpkg_log_entry->status() / status
221              
222             Get or set the status of the package this entry refers to.
223              
224             =cut
225             sub status {
226 3     3 1 10 my ($self, $status) = @_;
227              
228 3 50       15 if ($status) {
229 0         0 $self->{'status'} = $status;
230             } else {
231 3         10 $status = $self->{status}
232             }
233 3         22 return $status;
234             }
235              
236             =item $dpkg_log_entry->subject() / subject
237              
238             Gets or Defines the subject of the entry. For startup lines this is usually 'archives' or 'packages'
239             for all other lines its 'package'.
240              
241             =cut
242              
243             sub subject {
244 7     7 1 17 my ($self, $subject) = @_;
245              
246 7 50       18 if ($subject) {
247 0         0 $self->{subject} = $subject;
248             } else {
249 7         17 $subject = $self->{subject};
250             }
251 7         57 return $subject;
252             }
253              
254             =item $dpkg_log_entry->installed_version() / installed_version
255              
256             Gets or Defines the installed_version of the package this entry refers to.
257             It refers to the current installed version of the package depending on the
258             current status. Is "" (or similar) if action is 'install', old version in
259             case of an upgrade.
260             =cut
261             sub installed_version {
262 4     4 1 11 my ($self, $installed_version) = @_;
263              
264 4 50       12 if ($installed_version) {
265 0         0 $self->{'installed_version'} = $installed_version;
266             } else {
267 4         12 $installed_version = $self->{installed_version};
268             }
269 4         27 return $installed_version;
270             }
271              
272             =item $dpkg_log_entry->available_version() / available_version
273              
274             Gets or Defines the available_version of the package this entry refers to.
275             It refers to the currently available version of the package depending on the
276             current status. Is different from installed_version if the action is install or upgrade.
277             =cut
278             sub available_version {
279 1     1 1 4 my ($self, $available_version) = @_;
280 1 50       5 if ($available_version) {
281 0         0 $self->{'available_version'} = $available_version;
282             } else {
283 1         4 $available_version = $self->{available_version};
284             }
285 1         8 return $available_version;
286             }
287              
288             =item $dpkg_log_entry->conffile() / conffile
289              
290             Get or set a conffile for a line indicating a conffile change.
291              
292             =cut
293             sub conffile {
294 0     0 1   my ($self, $conffile) = @_;
295 0 0         if ($conffile) {
296 0           $self->{conffile} = $conffile;
297             } else {
298 0           $conffile = $self->{conffile};
299             }
300             }
301              
302             =item $dpkg_log_entry->decision() / decision
303              
304             Gets or defines the decision for a line indicating a conffile change.
305              
306             =cut
307             sub decision {
308 0     0 1   my ($self, $decision) = @_;
309 0 0         if ($decision) {
310 0           $self->{decision} = $decision;
311             } else {
312 0           $decision = $self->{decision}
313             }
314             }
315              
316             =back
317              
318             =head1 SEE ALSO
319              
320             L
321              
322             =head1 AUTHOR
323              
324             Patrick Schoenfeld .
325              
326             =head1 COPYRIGHT AND LICENSE
327              
328             Copyright (C) 2011 Patrick Schoenfeld
329              
330             This library is free software.
331             You can redistribute it and/or modify it under the same terms as perl itself.
332              
333             =cut
334              
335             1;
336             # vim: expandtab:ts=4:sw=4