Data-Conveyor
view release on metacpan or search on metacpan
lib/Data/Conveyor/Ticket/Transaction.pm view on Meta::CPAN
use 5.008;
use strict;
use warnings;
package Data::Conveyor::Ticket::Transaction;
BEGIN {
$Data::Conveyor::Ticket::Transaction::VERSION = '1.103130';
}
# ABSTRACT: Stage-based conveyor-belt-like ticket handling system
#
# Represents a single transaction as selected by txsel
use parent 'Class::Scaffold::Storable';
__PACKAGE__->mk_scalar_accessors(qw(
payload_item object_type command type status necessity
));
sub is_optional {
my $self = shift;
$self->necessity eq $self->delegate->TXN_OPTIONAL;
}
sub update_status {
my ($self, $ticket) = @_;
# Apply a default value, but don't change transactions that are set to
# TXS_IGNORE. This is relevant if you manually delete exceptions (via a
# service interface) - then you also want to reset transaction stati.
$self->status($self->delegate->TXS_RUNNING)
if $self->status eq $self->delegate->TXS_ERROR;
return unless $self->payload_item->has_problematic_exceptions($ticket);
$self->status($self->delegate->TXS_ERROR);
}
# Check that the current transaction's command is allowed for the ticket's
# type. For example, a 'perscreate' must only contain 'create' commands.
#
# Don't check the value objects this transaction object consists of, like we
# do with business objects - we generated the transaction object, and we
# expect it to be correct. It should have been created with checks on, so
# illegal arguments should have been spotted then and there (probably in the
# txsel).
#
# Note that exceptions are recorded not into the exception container this
# method is given in the second arg, but into the exception container of the
# payload item this transaction points to. That's because update_status() checks
# the referenced payload item's exception container to see whether to set this
# transaction's status to TXS_ERROR; an illegal transaction given the current
# ticket type should certainly be considered a problematic exception.
sub check {
my ($self, $ticket) = @_[0,2];
$self->check_policy_allowed_tx_for_ticket_type($ticket);
}
sub check_policy_allowed_tx_for_ticket_type {
my ($self, $ticket) = @_;
return
if $self->storage->policy_allowed_tx_for_ticket_type(
ticket_type => $ticket->type,
object_type => $self->object_type,
command => $self->command,
txtype => $self->type,
);
throw Data::Conveyor::Exception::CommandDenied(
ticket_type => $ticket->type,
object_type => $self->object_type,
command => $self->command,
);
}
use constant SKIP_COMPARABLE_KEYS => ('payload_item');
1;
__END__
=pod
=head1 NAME
Data::Conveyor::Ticket::Transaction - Stage-based conveyor-belt-like ticket handling system
=head1 VERSION
version 1.103130
( run in 0.724 second using v1.01-cache-2.11-cpan-d8267643d1d )