Osgood::EventList - A list of Osgood events.


Osgood-Client documentation Contained in the Osgood-Client distribution.

Index


Code Index:

NAME

Top

Osgood::EventList - A list of Osgood events.

DESCRIPTION

Top

A list of events.

SYNOPSIS

Top

  my $list = Osgood::EventList->new;
  $list->add_to_events($event);
  print $list->size."\n";

METHODS

Top

Constructor

new

Creates a new Osgood::EventList object.

add_to_events

Add the specified event to the list.

events

Set/Get the ArrayRef of events in this list.

iterator

Returns a MooseX::Iterator for iterating over events.

size

Returns the number of events in this list.

get_highest_id

Retrieves the largest id from the list of events. This is useful for keeping state with an external process that needs to 'remember' the last event id it handled.

AUTHOR

Top

Cory 'G' Watson <gphat@cpan.org>

SEE ALSO

Top

perl(1), Osgood::Event

COPYRIGHT AND LICENSE

Top


Osgood-Client documentation Contained in the Osgood-Client distribution.
package Osgood::EventList;
use Moose;
use MooseX::AttributeHelpers;
use MooseX::Iterator;
use MooseX::Storage;

with Storage('format' => 'JSON', 'io' => 'File');

has 'events' => (
    metaclass => 'Collection::Array',
    is => 'rw',
    isa => 'ArrayRef',
    default => sub { [] },
    provides => {
        push => 'add_to_events',
        count => 'size'
    }
);

has 'iterator' => (
    metaclass => 'Iterable',
    iterate_over => 'events'
);

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

	my $high = undef;
	foreach my $event (@{ $self->events }) {
		if(!defined($high) || ($high < $event->id)) {
			$high = $event->id;
		}
	}

	return $high;
}

__PACKAGE__->meta->make_immutable;

1;