App::Grepl::Results - PPI-powered grep results object


App-Grepl documentation Contained in the App-Grepl distribution.

Index


Code Index:

NAME

Top

App::Grepl::Results - PPI-powered grep results object

VERSION

Top

Version 0.01

SYNOPSIS

Top

OO interface to grepl's results

    use App::Grepl::Results;

    my $found = App::Grepl::Results->new( {
        file     => $file,
    } );
    $found->add_results( $token => \@results );

    print $found->file, "\n";
    while ( my $result = $found->next ) {
        print $result->token, "matched:\n";
        while ( my $item = $result->next ) {
            print "\t$item\n";
        }
    }

METHODS

Top

Class Methods

new

    my $grepl = App::Grepl::Results->new( { file => $file } );

Instance Methods

file

 my $file = $result->file;
 $result->file($file);

Get or set the filename the results pertain to. Will croak if the file does not exist.

have_results

 if ( $found->have_results ) { ... }

Boolean accessor indicating if we have results for the search.

add_results

 $found->add_results( 'heredoc' => \@array_ref_of_strings );

Add results to the result object. Takes two arguments:

* token

This should be a string representing the result type (e.g., comment, pod, etc).

Will croak if App::Grepl does not recognize the result type.

* results

This should be an array reference of strings. These are the actual results.

Will croak if something other than an array reference is passed.

filename_only

 if ( $result->filename_only ) {
     ...
 }
 $result->filename_only(1);

A boolean getter/setter for whether or not results are 'filename only'. These are returned to indicated that a file matched the criteria. The actual matches will not be returned.

next

 while ( defined ( my $result = $found->next ) ) {
     ...
 }

Returns the next result found.

Will croak if results are requested from a 'filename_only' object.

Note that the iterator is destructive.

AUTHOR

Top

Curtis Poe, <ovid at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-app-grepl at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Grepl. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc App::Grepl::Results

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/App-Grepl

* CPAN Ratings

http://cpanratings.perl.org/d/App-Grepl

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-Grepl

* Search CPAN

http://search.cpan.org/dist/App-Grepl

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


App-Grepl documentation Contained in the App-Grepl distribution.
package App::Grepl::Results;

use warnings;
use strict;
use App::Grepl;
use App::Grepl::Results::Token;

use base 'App::Grepl::Base';
use Scalar::Util 'reftype';

our $VERSION = '0.01';

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

    $self->file( delete $arg_for->{file} );
    $self->{results} = [];
    return $self;
}

sub file {
    my $self = shift;
    return $self->{file} unless @_;
    my $file = shift;
    unless ( -e $file ) {
        $self->_croak("Cannot find file ($file)");
    }
    $self->{file} = $file;
    return $self;
}

sub have_results { return scalar @{ shift->{results} } }

sub add_results {
    my ( $self, $elem, $results ) = @_;
    push @{ $self->{results} } => App::Grepl::Results::Token->new( {
        token => $elem,
        results => $results,
    } );
    return $self;
}

sub filename_only {
    my $self = shift;
    return $self->{filename_only} unless @_;
    my $filename_only = shift;
    $self->{filename_only} = $filename_only;
    return $self;
}

sub next {
    my $self = shift;
    if ( $self->filename_only ) {
        $self->_croak("No results available for 'filename_only' results objects");
    }
    my $next = shift @{ $self->{results} };
}

1;