This file is indexed.

/usr/share/perl5/Lire/ReportParser.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
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
package Lire::ReportParser;

use strict;

use base qw/ Lire::DocBookParser Lire::Config::Parser /;

use Lire::Report::TableInfo;
use Lire::Config::ListSpec;
use Lire::Config::ChartSpec;

=pod

=head1 NAME

Lire::ReportParser - Lire::XMLParser which parses XML reports

=head1 SYNOPSIS

    package MyParser;

    use base qw/ Lire::ReportParser /;

    sub parse_end {
        return "Finished";
    }

    package main::

    my $parser = new MyParser;
    my $result = eval { $parser->parsefile( "report.xml" ) };
    croak "Error parsing report.xml: $@" if $@
    print $result, "\n";

=head1 DESCRIPTION

This is a Lire::XMLParser(3pm) subclass which handle XML document
adhering to the Lire Report Markup Language format. It's primary
purpose is to write custom handlers for the Lire XML Report format.

=head1 USAGE

You create an instance of a subclass of Lire::ReportParser and use
either one of the parse() or parsefile() methods to process the XML
reports. You'll probably never use the Lire::ReportParser module
directly; you'll likely use one subclass which actually does something when
processing the document.

=head2 new( %args )


    my $parser = new Lire::ReportParser::ReportBuilder();

The new() method takes parameters in the form of 'key' => value pairs. The
available parameters are specific to each processor. There are no
generic parameters.

=cut

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

    return { %{$self->Lire::Config::Parser::namespaces()},
             'http://www.logreport.org/LRML/' => 'lire' };
}

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

    return {
            %{$self->Lire::Config::Parser::elements_spec()},
            %{$self->Lire::DocBookParser::elements_spec()},
            'lire:report' => [ 'lire:title', 'lire:date', 'lire:timespan',
                               'lire:description', 'lire:section' ],
            'lire:section' => [ 'lire:title', 'lire:description',
                                'lire:subreport', 'lire:missing-subreport' ],
            'lire:subreport' => [ 'lire:title', 'lire:description',
                                  'lire:chart-configs', 'lire:table' ],
            'lire:missing-subreport' => [],
            'lire:title' => [ 'PCDATA' ],
            'lire:description' => [ @Lire::DocBookParser::top_levels ],
            'lire:date' => [ 'PCDATA' ],
            'lire:timespan' => [ 'PCDATA' ],
            'lire:table' => [ 'lire:table-info', 'lire:group-summary',
                              'lire:entry' ],
            'lire:entry' => [ 'lire:name', 'lire:value', 'lire:group' ],
            'lire:name' => [ 'PCDATA' ],
            'lire:value' => [ 'PCDATA' ],
            'lire:group' => [ 'lire:group-summary', 'lire:entry' ],
            'lire:chart-configs' => [ 'lrcml:param' ],
            'lire:table-info' => [ 'lire:column-info', 'lire:group-info' ],
            'lire:group-info' => [ 'lire:column-info', 'lire:group-info' ],
            'lire:column-info' => [],
            'lire:group-summary' => [ 'lire:value' ],
           }
}

=pod

=head1 WRITING AN XML REPORT PROCESSOR

Using Lire::ReportParser, one can write an XML report processor.

The programming model is similar to the expat event-based interface or
the well-known SAX model. The principal difference with those models
is that this module offers hooks specifically tailored for Lire's XML
reports. For example, instead of having one generic element-start
event, you have methods for each specific type of element, making it
easy to hook on only the elements you're interested in. It also
offers some functions that make it easy to determine the context
(always a difficulty in event-based programming).

If you are uncomfortable with that kind of programming, there is also
an object-oriented API available to the XML reports. That API is more
similar to DOM type of programming. Its principal drawback is that its
less performant since it has to parse the whole XML document in memory
to build an object representation. But if you need to "navigate" the
document, it's a lot better than the event-based API.

The main way of using that API to write a custom XML report handler is
by subclassing the Lire::ReportParser module and overriding the
functions related to the elements you are interested in.

There are 3 categories of methods you can override.

=over 4

=item Customization Methods

Those are methods that customize the way the Lire::ReportParser will
operate. The most important one is the new() "constructor".

=item Generic element methods

Those are methods that are invoked on each element before the more
specific or higher ones and can be used to hook before the other events
are synthesized.

=back

=head1 HIGH-LEVEL EVENT METHODS

For each element defined, an I<element_name>_start() and an
I<element_name>_end() method are invoked. For elements that contains
character data, an I<element_name>_char() method will also be invoked
altough, you probably want to hook onto the easier
handle_I<element_name>() methods in these cases.

When you override any of those mehod (except the
handle_I<element_name>() one), you B<must> invoke the parent method
also:

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

        $self->SUPER::subreport_start( $name, $attr );

        # Processor specific handling.
    }

=head2 report_start( $name, $attr )

Called when the report element start tag is encountered.

The only defined attribute is C<version>. The current version is 2.0,
but older 1.0 report can still be parsed.

=cut

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

    $self->init_stack( 'config_spec' );
    $self->init_stack( 'config_value' );

    $self->error( "missing 'version' attribute on root element\n" )
      unless defined $attr->{'version'};

    $self->error( "'version' attribute should be 2.0 or 2.1: $attr->{'version'}")
      unless $attr->{'version'} eq '2.0' || $attr->{'version'} eq '2.1';

    $self->{'lrp_subreport_count'} = 0;

    return;
}

=pod

=head2 report_end( $name )

Called when the report element end tag is encountered.

=cut

sub report_end { }

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

    $self->collector_start( $name );

    return;
}

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

    $self->collector_char( $char );

    return;
}

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

    my $title = $self->get_collector( $name );
    $title =~ s/\s+/ /g;
    $self->handle_title( $title );

    return;
}

=pod

=head2 handle_title( $title )

Method invoked after the C<title> element was processed. The $title
parameter contains the content of the element. This can be a report's,
subreport's or section's title. You'll need to use the
in_element() method to determine the context.

=cut

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

    return;
}

=pod

=head2 handle_description( $docbook_desc )

Unless the description_start and description_end events are overriden
the content of the description will be collected and will be available
in the handle_description() method.

=cut

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

    $self->dbk_init();

    return;
}

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

    $self->handle_description( $self->dbk_string() );

    return;
}

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

    $self->{'lrp_curr_date'}  = { 'date' => '',
                                  'time' => $attr->{'time'} };
    return;
}

sub date_char {
    $_[0]->{'lrp_curr_date'}{'date'} .= $_[1];

    return;
}

sub date_end {
    my ( $self, $name ) = $_[0];

    $self->handle_date( $self->{'lrp_curr_date'}{'date'},
                        $self->{'lrp_curr_date'}{'time'} );

    return;
}

=pod

=head2 handle_date( $date, $date_epoch )

Called after the C<date> element was parsed. The formatted date is
available in the $date parameter, the date in number of seconds since
the epoch is available in the $date_epoch parameter.

This can be the report's or a subreport's date, you'll need to use the
in_element() method to determine the appropriate context.

=cut

sub handle_date {}

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

    $self->{'lrp_curr_timespan'} = { 'timespan' => '',
                                     'start' => $attr->{'start'},
                                     'end' => $attr->{'end'},
                                     'period' => $attr->{'period'} };

    return;
}

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

    $self->{'lrp_curr_timespan'}{'timespan'} .= $char;

    return;
}

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

    $self->handle_timespan( $self->{'lrp_curr_timespan'}{'timespan'},
                            $self->{'lrp_curr_timespan'}{'start'},
                            $self->{'lrp_curr_timespan'}{'end'},
                            $self->{'lrp_curr_timespan'}{'period'} );

    return;
}

=pod

=head2 handle_timespan( $timespan, $epoch_start, $epoch_end, $period )

Called after the C<timespan> element was parsed. The formatted
timespan is available in the $timespan parameter, starting and ending
dates of the timespan are available as number of seconds since the
epoch in the $epoch_start and $epoch_end parameters. The $period
parameter contians the timespan's period attribute.

This can be the timespan of the report or the subreport, you'll need
to use the in_element() method to determine the appropriate context.

=cut

sub handle_timespan {}


=pod

=head2 section_start( $name, $attr )

Called when the opening tag of a C<section> element is encountered.

=cut

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

    $self->{'lrp_section_subreport_count'} = 0;

    return;
}

=pod

=head2 section_end( $name )

Called when the closing tag of a C<section> element is encountered.

=cut

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

    $self->{'lrp_section_subreport_count'}    = 0;

    return;
}

=pod

=head2 missing_subreport_start( $name, $attr )

Called when the opening tag of a C<missing-subreport> element is
encountered. The C<superservice> attribute contains the superservice's
of the subreport, the C<type> attribute contains the report
specification ID and the C<reason> attribute will contains the reason
why the subreport is missing.

=cut

sub missing_subreport_start {}

=pod

=head2 missing_subreport_end( $name )

Called when the closing tag of a C<missing-subreport> element is
encountered.

=cut

sub missing_subreport_end {}

=pod

=head2 subreport_start( $name, $attr )

Called when the opening tag of the C<subreport> element is
encountered. The C<superservice> attribute contains the subreport's
superservice and the C<type> attribute contains the ID of the report
specification that was used to generate that subreport.

=cut

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

    $self->error( "missing 'superservice' attribute" )
      unless defined $attr->{'superservice'};
    $self->error( "missing 'type' attribute" )
      unless defined $attr->{'type'};

    $self->{'lrp_section_subreport_count'}++;

    $self->init_stack( 'lrp_group' );
    $self->init_stack( 'lrp_entry' );
    $self->{'lrp_subreport'} = $attr;

    return;
}

=pod

=head2 subreport_end( $name )

Called when the C<subreport>'s closing tag is encountered.

=cut

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

    $self->error( "ASSERTION failed: 'lrp_group' stack should be empty\n" )
      unless $self->is_stack_empty( 'lrp_group' );
    $self->error( "ASSERTION failed: 'lrp_group' stack should be empty\n" )
      unless $self->is_stack_empty( 'lrp_entry' );
    delete $self->{'lrp_subreport'};
    $self->{'lrp_curr_table_info'} = undef;
    $self->{'lrp_curr_group_info'} = undef;
    $self->{'lrp_subreport_count'}++;

    return;
}

=pod

=head2 table_start( $name, $attr )

Called when the opening tag of the C<table> element is encountered.
The C<show> attribute contains the maximum number of entries that
should be displayed (there may more entries than this number).

=cut

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

    $self->stack_push( 'lrp_group', { 'entry_count' => 0,
                                      'show' => $attr->{'show'},
                                    } );
    $self->{'lrp_curr_table'} = $self->stack_peek( 'lrp_group' );

    return;
}

=pod

=head2 table_end( $name )

Called when the C<table>'s closing tag is encountered.

=cut

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

    $self->stack_pop( 'lrp_group' );
    delete $self->{'lrp_curr_table'};

    return;
}

=pod

=head2 table_info_start( $name, $attr )

Called when the C<table-info>'s closing tag is encountered.

There should be no reason for subclasses to override this method. The
Lire::ReportParser takes care of parsing the C<table-info> content and
offers that information through a Lire::Report::TableInfo object which
is accessible through the current_table_info() method.

=cut

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

    $self->{'lrp_curr_table_info'} = new Lire::Report::TableInfo();

    $self->init_stack( 'lrp_group-info' );
    $self->stack_push( 'lrp_group-info', $self->{'lrp_curr_table_info'} );

    return;
}

=pod

=head2 table_info_end( $name )

Called when the C<table-info>'s closing tag is encountered. See
table_info_start() documentation for important comments.

=cut

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

    $self->stack_pop( 'lrp_group-info' );
    $self->stack_peek( 'lrp_group' )->{'group_info'} =
      $self->current_table_info();

    $self->error( "ASSERTION failed: stack 'lrp_group-info' should be empty" )
      unless $self->is_stack_empty( 'lrp_group-info' );

    return;
}

=pod

=head2 group_info_start( $name, $attr )

Called when the C<group-info>'s opening tag is encountered. See
table_info_start() documentation for important comments.

=cut

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

    my $curr_info = $self->stack_peek( 'lrp_group-info' );
    $self->stack_push( 'lrp_group-info',
                       $curr_info->create_group_info( $attr->{'name'} ) );

    return;
}

=pod

=head2 group_info_end( $name )

Called when the C<group-info>'s closing tag is encountered. See
table_info_start() documentation for important comments.

=cut

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

    $self->stack_pop( 'lrp_group-info' );

    return;
}

=pod

=head2 column_info_start( $name, $attr )

Called when the C<column-info>'s opening tag is encountered. See
table_info_start() documentation for important comments.

=cut

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

    my $group_info = $self->stack_peek( 'lrp_group-info' );
    my $info = $group_info->create_column_info( $attr->{'name'},
                                                $attr->{'class'},
                                                $attr->{'type'},
                                                $attr->{'label'} );
    $info->max_chars( $attr->{'max-chars'} );
    $info->avg_chars( $attr->{'avg-chars'} );
    $info->col_start( $attr->{'col-start'} );
    $info->col_end( $attr->{'col-end'} );
    $info->col_width( $attr->{'col-width'} );

    return;
}

=pod

=head2 column_info_end( $name )

Called when the C<column-info>'s closing tag is encountered. See
table_info_start() documentation for important comments.

=cut

sub column_info_end {}

=pod

=head2 group_summary_start( $name, $attr )

Called when the C<group-summary>'s opening tag is encountered.

=cut

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

    return;
}

=pod

=head2 group_summary_end( $name )

Called when the C<group-summary>'s closing tag is encountered.

=cut

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

    return;
}

=pod

=head2 group_start( $name, $attr )

Called when the opening tag of the C<group> element is encountered.
C<group> elements introduce a kind of nested table. The C<show>
attribute contains the maximum number of entries that should be
displayed, altough more entries may be present in the report.

=cut

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

    my $entry = $self->stack_peek( 'lrp_entry' );
    $entry->{'child_idx'}++;

    my $info = $entry->{'group_info'}->info_by_index( $entry->{'child_idx'} );
    $self->stack_push( 'lrp_group', { 'entry_count' => 0,
                                      'show'        => $attr->{'show'},
                                      'group_info'  => $info,
                                    } );

    return;
}

=pod

=head2 group_end( $name )

Called when the C<group>'s closing tag is encountered.

=cut

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

    $self->stack_pop( 'lrp_group' );

    return;
}

=pod

=head2 entry_start( $name, $attr )

Called when the opening tag of an C<entry> element is encountered.

=cut

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

    my $group = $self->stack_peek( 'lrp_group' );
    $group->{'entry_count'}++;

    $self->stack_push( 'lrp_entry', { %$attr,
                                      'child_idx'  => -1,
                                      'group_info' => $group->{'group_info'},
                                    } );

    return;
}

=pod

=head2 entry_end( $name )

Called when the C<entry>'s closing tag is encountered.

=cut

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

    $self->stack_pop( 'lrp_entry' );

    return;
}

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

    my $entry = $self->stack_peek( 'lrp_entry' );
    $entry->{'child_idx'}++;

    my $info =
      ( $attr->{'col'}
        ? $self->current_table_info()->column_info_by_name( $attr->{'col'} )
        : $entry->{'group_info'}->info_by_index( $entry->{'child_idx'} ) );

    $self->{'lrp_curr_name'} = { %$attr,
                                 'content' => "",
                                 'col_info' => $info,
                               };

    return;
}

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

    $self->{'lrp_curr_name'}{'content'} .= $char;

    return;
}

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

    $self->{'lrp_curr_name'}{'value'} = $self->{'lrp_curr_name'}{'content'}
      unless defined $self->{'lrp_curr_name'}{'value'};

    $self->handle_name( $self->{'lrp_curr_name'} );

    return;
}

=pod

=head2 handle_name( $name_rec )

Called after a C<name> element was parsed. The $name_rec parameter is
an hash reference which contains the different values of the name
datum. Keys that are defined in this hash:

=over 4

=item content

That's the actual content of the name element. This contains the name
in a format suitable for display.

=item value

This contains the unformatted value of the name. For example, when the
name is a time string, this attribute will contains the time in
seconds since epoch.

=item range

For some names, the actual content express a range (time, size, etc.).
This attribute contains the length of the range.

=item col_info

The Lire::ColumnInfo object describing the column in which this
name appears.

=back

=cut

sub handle_name {}

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

    # Value in group-summary are handled differently because
    # they aren't part of the entry children.
    $self->stack_peek( 'lrp_entry' )->{'child_idx'}++
      unless $self->within_element( "lire:group-summary" );

    $self->{'lrp_curr_value'} = { %$attr,
                                  'content' => "",
                                  'col_info' => $self->current_table_info()->column_info_by_name( $attr->{'col'} ),
                                };

    return;
}

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

    $self->{'lrp_curr_value'}{'content'} .= $char;

    return;
}

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

    $self->{'lrp_curr_value'}{'value'} = $self->{'lrp_curr_value'}{'content'}
      unless defined $self->{'lrp_curr_value'}{'value'};

    if ( $self->within_element( "lire:group-summary" ) ) {
        $self->handle_summary_value( $self->{'lrp_curr_value'} );
    } else {
        $self->handle_value( $self->{'lrp_curr_value'} );
    }

    return;
}

=pod

=head2 handle_value( $value_rec )

Called after a C<value> element was parsed. The $value_rec parameter is
an hash reference which contains the different values of the value
datum. Keys that are defined in this hash:

=over 4

=item content

That's the actual content of the value element. This contains the
value in a format suitable for display.

=item value

This contains the unformatted value. For example, when bytes are
displayed using "1M" or "1.1G", this will contains the value in bytes.

=item total

This is used by values that represent an average. It contains the
total which makes up the average.

=item n

This is used by values that represent an average. It contains the
total which was used in the division to compute the average.

=item col_info

The Lire::ColumnInfo object describing the column in which this
name appears.

=back

=cut

sub handle_value {}

=pod

=head2 handle_summary_value( $value_rec )

Called after a C<value> element located in the group-summary element
was parsed. The $value_rec parameter is identical than in the
handle_value() method.

=cut

sub handle_summary_value {}

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

    my $spec = new Lire::Config::ListSpec( 'name' => 'chart_configs' );
    $spec->add( new Lire::Config::ChartSpec( 'name' => 'chart' ) );
    $self->stack_push( 'config_spec', $spec );
    $self->stack_push( 'config_value', $spec->instance() );

    return;
}

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

    $self->stack_pop( 'config_spec' );
    $self->handle_chart_configs( $self->stack_pop( 'config_value' )->as_value() );

    return;
}

=pod

=head2 handle_chart_configs( $configs )

If the Subreport contained chart configurations, an array reference of
Lire::Report::ChartConfig objects will be passed to this event handler.

=cut

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

    return;
}

=pod

=head1 CONTEXT METHODS

Finally, here a bunch of additional methods that can be used to query
some context information when processing elements.

=cut

=pod

=head2 current_subreport_count( )

Returns the number of subreport that are present to date in the
report. That number is equals to the number of processed C<subreport>
elements, i.e. the current subreport isn't counted untill the closing
tag was processed.

=cut

sub current_subreport_count {
    return $_[0]{'lrp_subreport_count'};
}

=pod

=head2 current_section_subreport_count( )

Returns the number of subreport that are present to date in the
section. That number is equals to the number of processed C<subreport>
elements, i.e. the current subreport isn't counted untill the closing
tag was processed.

=cut

sub current_section_subreport_count {
    return $_[0]{'lrp_section_subreport_count'};
}

=pod

=head2 current_date( )

Returns the content of the C<date> element that applies to the current
element. This will either be the current subreport's date or the
default one taken from the C<report> element.

The date is returned as an hash reference which will contain the
formatted date in the C<date> key and the date in seconds since epoch
in the C<time> key.

=cut

sub current_date {
    return $_[0]{'lrp_curr_date'};
}


=pod

=head2 current_timespan( )

Returns the content of the C<timespan> element that applies to the
current element. This will either be the current subreport's date or
the default one taken from the C<report> element.

The timespan is returned as an hash reference which will contain the
formatted timespan in the C<timespan> key. The starting and ending
date of the timespan are available as seconds since epoch in the
C<start> and C<end> keys. The C<period> key contains the report's
timespan.

=cut

sub current_timespan {
    return $_[0]{'lrp_curr_timespan'};
}

=pod

=head2 current_superservice( )

Useful in C<subreport> context, it returns the superservice's of the
current subreport.

=cut

sub current_superservice {
    return $_[0]{'lrp_subreport'}{'superservice'};
}

=pod

=head2 current_type( )

Useful in C<subreport> context, it returns the ID of the report
specification that was used to generate the current subreport.

=cut

sub current_type {
    return $_[0]{'lrp_subreport'}{'type'};
}

=pod

=head2 current_table_info()

Useful when processing C<group> and C<entry>, this returns a
Lire::Report;:TableInfo object which describes the layout of the
current table.

=cut

sub current_table_info {
    return $_[0]{'lrp_curr_table_info'};
}

=pod

=head2 current_group_entry_show( )

Useful in C<table> and C<group> context, it returns the maximum number
of entries that should be displayed.

=cut

sub current_group_entry_show {
    return $_[0]->stack_peek( 'lrp_group' )->{'show'};
}

=pod

=head2 show_current_entry( )

Useful in C<entry> context , this can be used to test whether or not
the current C<entry> should be displayed based on the current entry
index and the parent's C<show> attribute.

=cut

sub show_current_entry {
    my $group = $_[0]->stack_peek( 'lrp_group' );

    return ( !defined $group->{'show'}
             || $group->{'entry_count'} <= $group->{'show'} );
}

=pod

=head2 current_table_entry_count( )

Useful in C<table> context, it returns the number of entries that were
processed so far. This only reports the entries in the C<table>
element, not counting the one in the nested C<group>.

=cut

sub current_table_entry_count {
    return $_[0]{'lrp_curr_table'}{'entry_count'};
}

1;

__END__

=pod

=head1 SEE ALSO

 Lire::Report(3pm), Lire::XMLParser(3pm)
 Lire::ReportParser::AsciiDocBookFormatter(3pm),
 Lire::ReportParser::AsciiWriter(3pm),
 Lire::ReportParser::HTMLDocBookFormatter(3pm),
 Lire::ReportParser::HTMLWriter(3pm),
 Lire::ReportParser::ReportBuilder(3pm),
 Lire::ReportParser::ExcelWriter(3pm),
 Lire::Report::TableInfo(3pm)

=head1 AUTHOR

  Francis J. Lacoste <flacoste@logreport.org>

=head1 VERSION

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

=head1 COPYRIGHT

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