package MooseX::Workers::ScheduledJob::Object;
use strict;
use Moose;

extends qw(MooseX::Workers::ScheduledJob);

has classname => (
    isa      => 'Str',
    is       => 'rw',
    lazy     => 1,
    required => 1,
    default  => 'NoClassSupplied',
);

has method => (
    isa      => 'Str',
    is       => 'rw',
    required => 1,
    default  => 'run',
);

has '+command' => (
    lazy     => 1,
    default  => sub {
        my $self = shift;

        my $class = $self->classname;
        Class::MOP::load_class($class)
          || die "Could not load class $class";
        my $obj = eval { $class->new };
        confess "Couldn't create instance of $class: $@" if $@;

        my $method = $obj->can( $self->method );
        confess "$class doesn't have a ".$self->method." method"
            unless defined $method;

        return $method;
    },
);

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