This file is indexed.

/usr/share/perl5/Lire/Report.pm is in lire 2:2.1.1-2.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
package Lire::Report;

use strict;

use Carp;
use POSIX qw/ strftime /;

use Lire::DataTypes qw/ check_superservice check_number /;
use Lire::I18N qw/ set_fh_encoding /;
use Lire::Utils qw/ xml_encode check_param check_object_param /;

=pod

=head1 NAME

Lire::Report - Interface to a Lire report.

=head1 SYNOPSIS

    use Lire::ReportParser::ReportBuilder;
    my $parser = new Lire::ReportParser::ReportBuilder;
    my $report = $parser->parse( "report.xml" );

    print $report->superservice(), " report\n";
    print "Generated on ", scalar( localtime( $report->date() ) ), "\n";
    print "Timespan starts on ", scalar( localtime( $report->timespan_start() ) ), "\n";
    print "Timespan ends on ", scalar( localtime( $report->timespan_start() ) ), "\n";
    foreach my $s ( $report->sections() ) {
        print "Section: '", $s->title(), "' has ", scalar $s->subreports(),
            " subreports in it\n";
    }

=head1 DESCRIPTION

This module offers an API to the report generated by Lire. The
Lire::ReportParser::ReportBuilder(3pm) can be used to create a
Lire::Report object from an XML file that complies with the Lire Report
Markup Language DTD.

=head1 CONSTRUCTOR

A Lire::Report object can be built from an XML report file, from the
new() method or from a Lire::ReportConfig object.

=head2 new( [ $timespan_period ], [ $timespan_start ], [ $timespan_end ] )

Creates a new Lire::Report. The $timespan_period, $timespan_start and
$timespan_end parameters initialize the attributes of the same name.

=cut

sub new {
    my ( $class, $period, $start, $end ) = @_;

    my $self = bless { '_version' => "2.1",
                       '_generator' => __PACKAGE__ . "(3pm)",
                       '_date'  => time,
                       '_start' => undef,
                       '_end' => undef,
                       '_period' => undef,
                       '_sections' => [],
                     }, $class;
    $self->timespan_period( $period ) if defined $period;
    $self->timespan_start( $start ) if defined $start;
    $self->timespan_end( $end ) if defined $end;

    return $self;
}

=pod

=head1 OBJECT METHODS

=head2 version()

Returns the version number of the report format which was used in the
external representation of this report. The current version is 2.1.

=cut

sub version {
    return $_[0]{'_version'};
}

=pod

=head2 generator([$generator)

Returns the generator string that will be outputted in comments when
the write_report() method is used. One can change that value by
passing a new value through the $generator parameter.

=cut

sub generator {
    $_[0]{'_generator'} = $_[1] if defined $_[1];
    return $_[0]{'_generator'};
}

=pod

=head2 date( [ $new_date ] )

Returns (and optionanly changes) the date in seconds since
epoch on which this report was generated.

=cut

sub date {
    my ( $self, $date ) = @_;

    if ( @_ == 2 ) {
        check_param( $date, 'date', \&check_number,
                     "'date' parameter should be a number of seconds since the epoch" );
        $self->{'_date'} = $date;
    }
    return $self->{'_date'};
}

=pod

=head2 timespan_period( [ $new_period ] )

Returns (and optionnally changes) the period of the report. The period
can be 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'. When the
period is undef, it is an arbitrary period.

=cut

sub timespan_period {
    my ( $self, $period ) = @_;

    if ( @_ == 2 ) {
        check_param( $period, 'period', 
                     qr/^(hourly|daily|weekly|monthly|yearly)$/,
                     "'period' parameter should be one of 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'" )
          if defined $period;
        $self->{'_period'} = $period;
    }

    return $self->{'_period'};
}

=pod

=head2 timespan_start( [ $new_start ] )

Returns (and optionnally changes) the start of the timespan covered by
this report in seconds since epoch.

=cut

sub timespan_start {
    my ( $self, $start ) = @_;

    if ( @_ == 2 ) {
        if ( $start ) {
            check_param( $start, 'start', \&check_number,
                         "'start' parameter should be a number of seconds since the epoch" );
            croak "'start' parameter is greater than timespan_end()"
              if $self->{'_end'} && $start > $self->{'_end'};
        }
        $self->{'_start'} = $start ? $start : undef;
    }
    return $self->{'_start'};
}

=pod

=head2 timespan_end( [ $new_end ] )

Returns (and optionnally changes) the end of the timespan covered by
this report in seconds since epoch.

=cut

sub timespan_end {
    my ( $self, $end ) = @_;

    if ( @_ == 2 ) {
        if ( $end ) {
            check_param( $end, 'end', \&check_number,
                         "'end' parameter should be a number of seconds since the epoch" );
            croak "'end' parameter is smaller than timespan_start()"
              if $self->{'_start'} && $end < $self->{'_start'};
        }
        $self->{'_end'} = $end ? $end : undef;
    }
    return $self->{'_end'};
}

=pod

=head2 title( [$title] )

Returns the report's title, if it has one.

If the $title is parameter is set, the report's title will be set to
this new value.

=cut

sub title {
    $_[0]{'title'} = $_[1] if @_ == 2;

    return $_[0]{'title'};
}

=pod

=pod

=head2 description( [$new_desc] )

Returns the report description. This description is encoded in DocBook
XML.

If the $description parameter is set, this method will set the
description to this new value. If the $description parameter is undef,
that description will be removed.

=cut

sub description {
    $_[0]->{'description'} = $_[1] if @_ == 2;

    return $_[0]->{'description'};
}

=pod

=head2 sections( )

Returns the report's sections as an array. This will be an array of
Lire::Report::Section objects.

=cut

sub sections {
    return @{$_[0]{'_sections'}};
}

=pod

=head2 add_section( $section )

Adds a section to this report. The $section parameter should be a
Lire::Report::Section object.

=cut

sub add_section {
    my ( $self, $section ) = @_;

    check_object_param( $section, 'section', 'Lire::Report::Section' );
    push @{$self->{'_sections'}}, $section;

    return;
}

=pod

=head2 subreport_by_id( $id )

Returns the Lire::Report::Subreport object with $id. Returns undef
when there is no subreport with that ID.

=cut

sub subreport_by_id {
    my ( $self, $id ) = @_;

    check_param( $id, 'id' );

    foreach my $section ( @{$self->{'_sections'}} ) {
        foreach my $subreport ( $section->subreports() ) {
            return $subreport if $subreport->id() eq $id;
        }
    }

    return undef;
}


=pod

=head2 schemas() 

Returns an array reference containing all the schemas used
by this report.

=cut

sub schemas {
    my $self = $_[0];

    my %schemas = ();
    foreach my $sect ( $self->sections() ) {
        foreach my $sub ( $sect->subreports() ) {
            foreach my $id ( @{$sub->schemas()} ) {
                $schemas{$id} = 1;
            }
        }
    }
    return [ sort keys %schemas ];
}

=pod

=head2 write_report( [FH] );

Write the report in XML format on the FH filehandle or STDOUT if
omitted.

This method takes care of adding stuff like the XML header C<E<lt>?xml
version=[...]>.  It encodes the XML report in UTF-8, using
Lire::I18N::set_fh_encoding().

=cut

sub write_report {
    my ( $self, $fh ) = @_;

    $fh ||= \*STDOUT;

    set_fh_encoding( $fh, 'UTF-8' );

    my $time  = strftime '%Y-%m-%d %H:%M:%S %Z', localtime $self->date();
    my $period_string = "";
    if ( $self->timespan_start() ) {
        my $stime = strftime( '%Y-%m-%d %H:%M:%S %Z',
                              localtime $self->timespan_start() );
        my $etime = strftime( '%Y-%m-%d %H:%M:%S %Z', 
                              localtime $self->timespan_end() );
        $period_string = "$stime - $etime";
    } else {
        $period_string = "Unknown Period";
    }

    print $fh <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE lire:report PUBLIC
  "-//LogReport.ORG//DTD Lire Report Markup Language V$self->{'_version'}//EN"
  "http://www.logreport.org/LRML/$self->{'_version'}/lrml.dtd">
<lire:report xmlns:lire="http://www.logreport.org/LRML/" xmlns:lrcml="http://www.logreport.org/LRCML/" version="$self->{'_version'}">
 <!-- generated by $self->{'_generator'} -->
EOF
    print $fh " <lire:title>", xml_encode( $self->title() ), "</lire:title>\n"
      if defined $self->title();

    print $fh ' <lire:date time="', $self->{'_date'}, '">', $time,
      "</lire:date>\n";
    {
        no warnings 'uninitialized';
        print $fh ' <lire:timespan ',
          ( $self->{'_period'} ? "period=\"$self->{'_period'}\" " : "" ),
            'start="', $self->{'_start'}, '" end="', $self->{'_end'}, '">',
              $period_string, "</lire:timespan>\n";
    }

    print $fh " <lire:description>", $self->description(),
      "</lire:description>\n\n"
        if ( $self->description() );

    foreach my $s ( $self->sections() ) {
        $s->write_report( $fh, 1 );
    }
    print $fh "</lire:report>\n";

    return;
}

# Creates an identifier for Subreport's type $type.
# This creates an ID that will make sure that the
# subreport would be merged identically than with the
# previous merging algorithm which didn't merge by id.
sub create_subreport_id {
    my ( $self, $type ) = @_;

    $self->{'_id_cache'}{$type} ||= 0;

    return $type . "." . $self->{'_id_cache'}{$type}++;
}


=pod

=head2 delete( )

Removes all circular references so that the object can be freed.

=cut

sub delete {
    my $self = $_[0];

    foreach my $s ( $self->sections() ) {
        foreach my $r ( $s->subreports() ) {
            $r->delete();
        }
    }

    return;
}

# keep perl happy
1;

__END__

=pod

=head1 SEE ALSO

Lire::ReportParser::ReportBuilder(3pm) Lire::Report::Section(3pm)
Lire::Report::Subreport(3pm) Lire::Report::Entry(3pm)
Lire::Report::Group(3pm)
Lire::ReportParser(3pm)

=head1 AUTHOR

  Francis J. Lacoste <flacoste@logreport.org>

=head1 VERSION

$Id: Report.pm,v 1.35 2006/07/23 13:16:29 vanbaal Exp $

=head1 COPYRIGHT

Copyright (C) 2002, 2004 Stichting LogReport Foundation LogReport@LogReport.org

This file is part of Lire.

Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html. 

=cut