Osgood::Event - An Osgood Event


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

Index


Code Index:

NAME

Top

Osgood::Event - An Osgood Event

DESCRIPTION

Top

Events are characterized by an object and an action, which could be though of as a noun and a verb. The date_occurred is also important and, hopefully, self-explanatory. To round out the event there is a params method that accepts a HashRef for name value pairs.

Note: object and action names are limited to 64 characters.

SYNOPSIS

Top

  my $event = Osgood::Event->new(object => 'Test', action => 'create');

METHODS

Top

new

Creates a new Osgood::Event object. Requires an object and action. If no date_occurred is specifed, then the DateTime-now> is used.

action

The action this event represents.

date_occurred

The date and time this event occurred

object

The object this event pertains to.

params

A HashRef of name-value pairs for this event.

set_param

Allows setting a single name value pair directly.

get_param

Get the value of the specifed key.

AUTHOR

Top

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

SEE ALSO

Top

perl(1), Osgood::EventList

COPYRIGHT AND LICENSE

Top


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

package Osgood::Event;
use Moose;
use MooseX::Storage;
use MooseX::AttributeHelpers;

use DateTime;
use DateTime::Format::ISO8601;

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

has 'id' => ( is => 'rw', isa => 'Int'  );
has 'action' => ( is => 'rw', isa => 'Str', required => 1 );
has 'date_occurred' => (
    is => 'rw',
    isa => 'DateTime',
    default => sub { DateTime->now }
);
has 'object' => ( is => 'rw', isa => 'Str', required => 1 );
has 'params' => (
    metaclass => 'Collection::Hash',
    is => 'rw',
    isa => 'HashRef',
    default => sub{ {} },
    provides => {
        get => 'get_param',
        set => 'set_param'
    }
);

MooseX::Storage::Engine->add_custom_type_handler(
    'DateTime' => (
        expand => sub { DateTime::Format::ISO8601->parse_datetime(shift) },
        collapse => sub { (shift)->iso8601 }
    )
);

__PACKAGE__->meta->make_immutable;

1;

__END__