package MooseX::Workers::Job;
use strict;
use Moose;
use Data::UUID;

use overload (
    '""'  => sub { $_[0]->uuid },
    '&{}' => sub {
        my ($self) = @_;
        ref $self->command eq 'CODE'
          ? sub { $self->command->( $self->args ) }
          : confess "Command isn't a code reference";
    },
    '@{}' => sub {
        my ($self) = @_;
        ref $self->command eq 'ARRAY'
          ? sub { $self->command, $self->args }
          : confess "Command isn't an array reference";
      }

);

has uuid => (
    isa      => 'Str',
    is       => 'ro',
    lazy     => 1,
    required => 1,
    default  => sub { Data::UUID->new()->create_str() },
);

has command => (
    isa      => 'Defined',
    is       => 'rw',
    required => 1,
);

has args => (
    isa        => 'ArrayRef',
    is         => 'rw',
    auto_deref => 1,
);

no Moose;  # unimport Moose's keywords so they won't accidentally become methods
1;         # Magic true value required at end of module
__END__
