package LCH::AppText; use strict; our $VERSION = 0.04; =head1 NAME LCH::AppText - Class for parsing application text (e.g. logfiles) =head1 SYNOPSIS use LCH::AppText local $/ = undef; my $apt = LCH::AppText->new(<>); my @revals = $apt->range(qr/itdFullRevalStarted/,qr/itdFullRevalEnded/); @flows = $revals[$i]->match(qr/read (\d+) cashflows/); =head1 DESCRIPTION This module allows application text to be parsed in suitable ways for analysis. =head2 new Pass in a string from an LCH application to create an LCH::AppText object. =head2 append Append to an existing LCH::AppText object =head2 split Return a list of LCH::AppText objects, begin a new one on each matching line. =head2 range Supply 2 regexs, one for the start of the range, one for the end. This method outputs a list of the ranges, as LCH::AppText objects. =head2 match Provide a regexp with captures. Returns a 2 dimensional array of capture returns within matching instances. =head1 AUTHOR Ivor Williams =head1 SEE ALSO perl(1). =cut sub new { my ($pkg, $text) = @_; my @self = split /^/,$text; bless \@self, $pkg ; } sub append { my ($self, $extra) = @_; push @$self, split /^/,$extra; } sub range { my ($self, $from, $to) = @_; my @out; my $ind = 0; for (@$self) { if (my $ff = /$from/ .. /$to/) { $out[$ind] .= $_; $ind++ if $ff =~ /E/; } } map {LCH::AppText->new($_)} @out; } sub split { my ($self, $match) = @_; my @out; my $ind = 0; for (@$self) { $ind++ if /$match/; $out[$ind] .= $_; } map {LCH::AppText->new($_)} @out; } sub text { my $self = shift; join '',@$self; } sub firstline { my $self = shift; $self->[0]; } sub lastline { my $self = shift; $self->[-1]; } sub match { my ($self, $re) = @_; my @out; for (@$self) { my @mat = /$re/; push @out,\@mat if @mat; } @out; } 1; #this line is important and will help the module return a true value __END__