This file is indexed.

/usr/share/perl5/Lire/Aggregate.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
package Lire::Aggregate;

use strict;

use base qw/ Lire::ReportOperator /;

use Carp;

use Lire::DataTypes qw/ check_field /;
use Lire::ReportOperator;
use Lire::Utils qw/ sql_quote_name check_param /;

=pod

=head1 NAME

Lire::Aggregate - Base class for all operators that compute values from a group
of DLF records

=head1 SYNOPSIS

    use Lire::Aggregate;

    use base qw/ Lire::Aggregate /;

=head1 DESCRIPTION

The Lire::Aggregate is the base class of all operators that computes
values from a group of DLF records. These are the operators that are
used inside aggregators.

This package also defines most of the classes that represents the
group operators available in Lire report specification.

=head1 METHODS FOR SUBCLASSES OF Aggregate

=head2 init( %params )

Two supplemental parameters are needed for Aggregates:

=over

=item parent

The Lire::Aggregator which contain this Aggregate. 

=item name

The identifier that can be used to find this operator in the report
specification. It will be returned by the name() method.

=back

=cut

sub init {
    my ( $self, %params ) = @_;

    check_param( $params{'parent'}, 'parent' );
    check_param( $params{'name'}, 'name' );

    $self->SUPER::init( %params );

    $self->set_name( $params{'name'} );
    return;
}

=pod

=head2 print( $fh, $prefix)

This methods implements the print() method required by
Lire::ReportOperator. It prints an empty XML element named after op().
It also takes care of writing the name and label attributes. Other
attributes can be added to the XML element by overriding the
xml_attrs() method.

=cut

sub print {
    my ($self,$fh, $prefix) = @_;
    $fh	    ||= \*STDOUT;
    $prefix ||= 0;

    my $pfx = " " x $prefix;
    my $attrs = $self->xml_attrs;

    print $fh $pfx, "<lire:", $self->op, ' name="', $self->name, '"';
    print $fh qq{ label="$self->{'label'}"}
      if $self->{'label'};
    print $fh $attrs if length $attrs;
    print $fh "/>\n";
}

=pod

=head2 xml_attrs()

This method can be used to write additional XML attributes. The
returned string will be output in the XML element.

=cut

sub xml_attrs {
    return "";
}

# Implemented Lire::ReportOperator::name
sub name {
    return $_[0]{'name'};
}

=pod

=head2 set_name( $name )

Changes this operator's name.

=cut

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

    check_param( $name, 'name', \&check_field, 'invalid field name' );

    croak "name '$name' is already defined"
      if defined $self->{'name'}
        && $name ne $self->{'name'}
        && $self->last_parent->is_name_defined( $name );

    $self->{'name'} = $name;

    return;
}

=pod

=head2 create_numerical_info( $group_info )

Subclass must implement this method.

The $group_info parameter is a Lire::Report::GroupInfo object to which
the operator implementation should add the appropriate ColumnInfo object to 
represent the data generated by the aggregate.

=cut

sub create_numerical_info {
    croak( "unimplemented create_numerical_info() method in ", ref $_[0] );
}

=pod

=head2 build_query( $query )

FIXME.

Provides a default implementation of build_query

=cut

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

    $query->add_aggr_field( $self->name(), $self->sql_aggr_expr() );

    $self->set_missing_cases_aggr_expr( $query );

    return;
}

=pod

=head2 set_missing_cases_aggr_expr( $query )

Adds the aggregate expression to compute the number of missing cases
based on the required fields returned by the sql_required_fields()
method.

The method set_missing_cases_value() can be used to set the value from
the returned DLF row.

=cut

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

    my $req_fields_expr = 
      join( ",", map { sql_quote_name( $_ ) } @{$self->sql_required_fields} );
    $query->add_aggr_field( '_lr_' . $self->name() . '_mc',
                            sprintf( 'lr_missing_cases(%s)',
                                     $req_fields_expr ) );

    return;
}

=pod

=head2 set_missing_cases_value( $row, $value )

Sets the missing-cases value in $value to the value computed by the
expression sets using set_missing_cases_aggr_expr().

=cut

sub set_missing_cases_value {
    my ( $self, $row, $value ) = @_;

    $value->{'missing_cases'} = $row->{'_lr_' . $self->name() . '_mc'};

    return;
}

=pod

=head2 sql_aggr_expr()

Method used by the default implementation of build_query(). It should
return the SQL agregate expression that should be associated to this
Aggregate's name. For example, a simple Count implementation could
have returned 'count(*)' here.

=cut

sub sql_aggr_expr {
    croak( "unimplemented sql_aggr_expr() method in ", ref $_[0] );
}

=pod

=head2 sql_required_fields()

Method used by the set_missing_cases_aggr_expr() to sets an aggregate
expression that will return the number of missing cases for this
aggregate. It should returns a list of fields that will create a
missing case when a value is NULL.

=cut

sub sql_required_fields {
    croak( "unimplemented sql_required_fields() method in ", ref $_[0] );
}

=pod

=head2 create_value( $parent_group, $row )

Method that is used by Aggregator when building the report table. The
report should return an hash reference with the appropriate keys set.
Consult Lire::Report::Entry(3pm) for details.

The $parent_group parameter is the Lire::Report::Group to which the
value is added. This will be the table or containing group for values
added to Entries, and it will be the Group's parent when creating a
summary value.

The $row parameter is an hash ref containing the DlfResult row for
which the value should be created.

Implementation should use the set_missing_cases_value() method to set
the value's 'missing_cases' attribute.

=cut

sub create_value {
    croak( "unimplemented create_value() method in ", ref $_[0] );
}

# Defines Lire::ReportOperator::init_merge()
sub init_merge {}

# Defines Lire::ReportOperator::end_merge()
sub end_merge {}

# OPTIMIZATION OF THE DATA STRUCTURE
#.
# Scalar ref takes less place then array refs which takes less spec
# then hash ref. We use only scalar or array refs.
#
# As a side effects, we also get a little speed optimization :
# perl -MBenchmark=cmpthese -e '
#   my $dummy = 0;
#   my $scalar = \$dummy;
#   my $array = [0]; 
#   my $hash = { 'value' => 0};
#   cmpthese( 500000, {
#		'SCALAR' => sub { $$scalar++ },
#		'ARRAY'  => sub { $array->[0]++ },
#		'HASH'   => sub { $hash->{'value'}++ },
#	     });
# Benchmark: timing 500000 iterations of ARRAY, HASH, SCALAR...
#     ARRAY:  0 wallclock secs ( 0.57 usr +  0.00 sys =  0.57 CPU) @ 877192.98/s (n=500000)
#     HASH:  1 wallclock secs ( 0.67 usr +  0.00 sys =  0.67 CPU) @ 746268.66/s (n=500000)
#    SCALAR:  1 wallclock secs ( 0.41 usr +  0.00 sys =  0.41 CPU) @ 1219512.20/s (n=500000)
#             Rate   HASH  ARRAY SCALAR
# HASH    746269/s     --   -15%   -39%
# ARRAY   877193/s    18%     --   -28%
# SCALAR 1219512/s    63%    39%     --
#
# Make default implementation uses a scalar reference
# Implements Lire::ReportOperator::init_group_data
sub init_group_data {
    my $scalar = 0;
    return \$scalar;
}

# Implements Lire::ReportOperator::end_group_data
sub end_group_data {}

# Implements Lire::ReportOperator::add_entry_value
sub add_entry_value {
    my ( $self, $entry, $data ) = @_;

    my $v = $self->create_value( $entry->group(), $self->data2dlf( $data ) );
    $entry->add_value( %$v );
    return;
}

# Method used by Lire::Aggregator:: to dispath to
# Lire::*::create_value()
sub data2dlf {
    croak "Unimplemented data2dlf() in ", ref $_[0];
}

#------------------------------------------------------------------------
# missing_cases( $data )
#
# This method returns the number of missing-cases encountered
# while processing $data.
sub missing_cases {
    my ( $self, $data );

    return 0 unless ( defined $self->{'_missing_cases'}
                      && defined $self->{'_missing_cases'}{$data} );
    return $self->{'_missing_cases'}{$data};
}

# keep perl happy
1;

__END__

=head1 SEE ALSO

Lire::ReportSpec(3pm), Lire::ReportOperator(3pm), Lire::Aggregator(3pm).

=head1 AUTHORS

  Francis J. Lacoste <flacoste@logreport.org>
  Wolfgang Sourdeau <wolfgang@logreport.org>

=head1 VERSION

$Id: Aggregate.pm,v 1.16 2006/07/23 13:16:27 vanbaal Exp $

=head1 COPYRIGHT

Copyright (C) 2001-2003 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