Jifty/Action/Record/Delete.pm

filter: Statementstmt 41.6% 10 / 24 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 38.1% 16 / 42 CC 5 SCAR 22.7
CC
5
Cov
32%
take_action
20.0
arguments
6.0
report_success
2.0
CRAP 9.7
« Jifty/Plugin/PubSub.pm ↑ Summary Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm »
1 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Jifty::Action::Record::Delete;
5  
6 =head1 NAME
7  
8 Jifty::Action::Record::Delete - Automagic delete action
9  
10 =head1 DESCRIPTION
11  
12 This class is used as the base class for L<Jifty::Action>s that are
13 merely deleting L<Jifty::Record> objects. To use it, subclass it and
14 override the C<record_class> method to return the name of the
15 L<Jifty::Record> subclass that this action should delete.
16  
17 =cut
18  
19 1 ▶use base qw/Jifty::Action::Record/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =head1 METHODS
22  
23 =head2 arguments
24  
25 Overrides the L<Jifty::Action::Record/arguments> method to specify
26 that all of the primary keys B<must> have values when submitted; that
27 is, they are L<constructors|Jifty::Manual::Glossary/constructors>. No other
28 arguments are required.
29  
30 =cut
31  
32 0 ▶sub arguments {
Subroutine arguments: not called CC=2 SCAR=17.9
Pod documented
33 0 my $self = shift;
34 0 my $arguments = {};
35  
36 # Mark the primary key for use in the constructor and not rendered
37 0 for my $pk (@{ $self->record->_primary_keys }) {
38 0 $arguments->{$pk}{'constructor'} = 1;
39 # XXX TODO IS THERE A BETTER WAY TO NOT RENDER AN ITEM IN arguments
40 0 $arguments->{$pk}{'render_as'} = 'Unrendered';
41 # primary key fields should always be hidden fields
42 }
43 0 return $arguments;
44 }
45  
46 =head2 take_action
47  
48 Overrides the virtual C<take_action> method on L<Jifty::Action> to
49 delete the row from the database.
50  
51 =cut
52  
53 0 ▶sub take_action {
Subroutine take_action: not called CC=4 SCAR=30.0
Pod documented
54 0 my $self = shift;
55  
56 # Delete the record and return an error if delete fails
57 0 my ( $val, $msg ) = $self->record->delete;
58 0 ▶ $self->result->error($msg || _('Permission denied')) if not $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
Condition0%0/3
$msg || _('Permission denied')
l!l&&r!l&&!r
000
MC/DC0%0/2
$msg || _('Permission denied')
$msg _('Permission denied')
Truth table0%0/3
A || B
A= $msgB= _('Permission denied')
ABresult
1X1
011
000
59  
60 # Otherwise, we seem to have succeeded, report that
61 0 ▶ $self->report_success if not $self->result->failure;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->result->failure 0 0 0
62  
63 0 return 1;
64 }
65  
66 =head2 report_success
67  
68 Sets the L<Jifty::Result/message> to default success message,
69 "Deleted". Override this if you want to report some other more
70 user-friendly result.
71  
72 =cut
73  
74 0 ▶sub report_success {
Subroutine report_success: not called CC=1 SCAR=6.9
Pod documented
75 0 my $self = shift;
76 0 $self->result->message(_("Deleted"))
77 }
78  
79 =head1 SEE ALSO
80  
81 L<Jifty::Action::Record>, L<Jifty::Record>
82  
83 =head1 LICENSE
84  
85 Jifty is Copyright 2005-2010 Best Practical Solutions, LLC.
86 Jifty is distributed under the same terms as Perl itself.
87  
88 =cut
89  
90 1 1;
« Jifty/Plugin/PubSub.pm ↑ Summary Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm »