use warnings; use strict; package Jifty::Action::Record::Delete; =head1 NAME Jifty::Action::Record::Delete - Automagic delete action =head1 DESCRIPTION This class is used as the base class for Ls that are merely deleting L objects. To use it, subclass it and override the C method to return the name of the L subclass that this action should delete. =cut use base qw/Jifty::Action::Record/; =head1 METHODS =head2 arguments Overrides the L method to specify that all of the primary keys B have values when submitted; that is, they are L. No other arguments are required. =cut sub arguments { my $self = shift; my $arguments = {}; for my $pk (@{ $self->record->_primary_keys }) { $arguments->{$pk}{'constructor'} = 1; # XXX TODO IS THERE A BETTER WAY TO NOT RENDER AN ITEM IN arguments $arguments->{$pk}{'render_as'} = 'Unrendered'; # primary key fields should always be hidden fields } return $arguments; } =head2 take_action Overrides the virtual C method on L to delete the row from the database. =cut sub take_action { my $self = shift; my ( $val, $msg ) = $self->record->delete; $self->result->error($msg) if not $val and $msg; $self->report_success if not $self->result->failure; return 1; } =head2 report_success Sets the L to default success message, "Deleted". Override this if you want to report some other more user-friendly result. =cut sub report_success { my $self = shift; $self->result->message(_("Deleted")) } 1;