module starter stuff
[Pqsl-Perl.git] / Lib / Query / File.pm
blobdecfa907d596ddce4f0db623b36f0dde33cb4934
1 package Lib::Query::File;
2 use Moose;
4 extends 'Lib::Query';
6 use IO::File;
8 has 'file' => (
9 isa => 'Str',
10 , is => 'ro'
11 , required => 1
14 has 'fh' => (
15 isa => 'IO::File'
16 , is => 'ro'
17 , lazy => 1
18 , default => \&get_fh
21 sub BUILD {
22 my $self = shift;
23 $self->get_rows
26 sub get_fh {
27 my $self = shift;
29 my $fh = IO::File->new( $self->file, 'r' );
31 $fh;
34 sub get_rows {
35 my $self = shift;
37 my $fh = $self->fh;
39 my @file = $fh->getlines;
41 chomp @file;
43 ## Preprocess
44 ## Shift off the header
45 until ( (shift @file) =~ /^-+$/ ) { next };
47 ## ammend the lack of consistancy with the first row
48 $file[0] = "-> $file[0]";
49 foreach ( @file[1..$#file] ) {
50 $_ = " $_";
53 my $row;
54 foreach my $line ( @file ) {
55 chomp $line;
57 next unless $line =~ /\S/;
58 ## Operation
59 if ( $line =~ /[.]{2}/ and $line !~ /:/ ) {
61 $row = Lib::Token::Row::Operation->new({
62 src => $line
63 });
64 $self->push_row( $row );
68 ## Footer Rows
69 elsif ( $line =~ /^Total runtime:\s+\d+.\d+\s*ms$/ ) {}
70 elsif ( $line =~ /^\(\d+ rows\)$/ ) {}
72 ## OperationalInfo
73 elsif ( $line !~ /^\s*->/ ) {
74 $row->add_operation_info_row( $line )