List::Analyse::Sequence - Analyse a list for sequences.


List-Analyse-Sequence documentation Contained in the List-Analyse-Sequence distribution.

Index


Code Index:

NAME

Top

List::Analyse::Sequence - Analyse a list for sequences.

VERSION

Top

Version 0.01

DESCRIPTION

Top

Given a list, analyse it for sequences. Sequences are defined by their Analyser classes, which are plugins to this module and are found under List::Analyse::Sequence::Analyser.

SYNOPSIS

Top

    use List::Analyse::Sequence;

    my $analyser = List::Analyse::Sequence->new();

    $analyser->use_these_analysers( $analyser->analysers );

    $analyser->analyse( @list );
    my @($valid_sequences, $invalid_sequences) = $analyser->result;

    # ... OR ... #

    while ( my $list_item = $some_iterator->next ) {
        $analyser->add( $list_item );
    }

    my ($valid_sequences, $invalid_sequences) = $analyser->result;

CONSTRUCTOR

Top

new

Creates a new sequence analyser.

METHODS

Top

analysers

Returns a list of available analysers. You can create an analyser by putting a module in somewhere that List::Analyse::Sequence::Analyser::* will find.

See List::Analyse::Sequence::Analyser for info.

use_these_analysers

Pick a bunch of analysers from $obj->analysers and provide them here. These will be used to analyse the list.

If you're feeling cocky then you should know that the list passed in is just a bunch of class names whose constructors are expected to be new().

analyse

Pass in a list of things to analyse. Each of your analysers will look at the list and decide whether or not the list adheres to its sequence definition.

add

An alternative to passing a list to analyse() is to pass a scalar to add. This will run each analyser on the added element.

This is especially useful for when you are using an iterator, or some form of lasagne code, for example.

result

Get the result of the analysis, as two arrayrefs. The first will contain those analysers whose sequence definitions were fulfilled by all items: the second will contain those that were discarded.

AUTHOR

Top

Alastair Douglas, <altreus at perl.org>

BUGS

Top

Please report any bugs or feature requests to bug-list-analyse-sequence at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=List-Analyse-Sequence. 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 List::Analyse::Sequence




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=List-Analyse-Sequence

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/List-Analyse-Sequence

* CPAN Ratings

http://cpanratings.perl.org/d/List-Analyse-Sequence

* Search CPAN

http://search.cpan.org/dist/List-Analyse-Sequence/

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


List-Analyse-Sequence documentation Contained in the List-Analyse-Sequence distribution.

package List::Analyse::Sequence;

use warnings;
use strict;

use Module::Pluggable (
    search      => [ "List::Analyse::Sequence::Analyser" ],
    sub_name    => 'analysers',
);
use List::MoreUtils qw(part);

our $VERSION = '0.01';

sub new {
    my $class   = shift;
    my $self    = bless {}, $class;

    return $self;
}

sub use_these_analysers {
    my $self    = shift;

    # Module::Pluggable does not give us the option of postponing
    # the require stage until we actually request the plugin be used.
    eval " CORE::require $_ " or warn $@ for @_; 
    $self->{analysers} = [map {$_->new} @_];
}

sub analyse {
    my $self    = shift;
    my @data    = @_;

    $self->add( $_ ) for @data;
}

sub add {
    my $self    = shift;
    my $datum   = shift;

    $self->{discard} ||= [];

    my ($discarded_analysers, $remaining_analysers)
        = part { $_->analyse( $datum ) ? 1 : 0 } @{ $self->{analysers} };

    $discarded_analysers ||= []; $remaining_analysers ||= [];

    $self->{analysers} = $remaining_analysers;
    push @{ $self->{discard} }, @$discarded_analysers;
}

sub result {
    my $self    = shift;

    # Some analysers may be lazy or may need to wait.
    $_->done for @{$self->{analysers}};

    return ($self->{analysers}, $self->{discard}) if wantarray;
    return $self->{analysers};
}

1;
__END__