File Coverage

blib/lib/Fey/ORM/Mock/Action.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Fey::ORM::Mock::Action;
2             {
3             $Fey::ORM::Mock::Action::VERSION = '0.06';
4             }
5              
6 1     1   29159 use strict;
  1         2  
  1         35  
7 1     1   5 use warnings;
  1         2  
  1         33  
8              
9 1     1   1604 use Moose;
  0            
  0            
10             use MooseX::StrictConstructor;
11             use Moose::Util::TypeConstraints;
12             use MooseX::Params::Validate qw( validate );
13              
14             has class => (
15             is => 'ro',
16             isa => 'ClassName',
17             required => 1,
18             );
19              
20             subtype 'Fey.Mock.ORM.ActionType' => as 'Str' =>
21             where { $_[0] =~ /^(?:insert|update|delete)$/ };
22              
23             has type => (
24             is => 'ro',
25             isa => 'Fey.Mock.ORM.ActionType',
26             required => 1,
27             );
28              
29             for my $type (qw( insert update delete )) {
30             my $attr = 'is_' . $type;
31              
32             my $t = $type;
33             has $attr => (
34             is => 'ro',
35             isa => 'Bool',
36             lazy => 1,
37             default => sub { $_[0]->type() eq $t },
38             );
39             }
40              
41             sub new_action {
42             my $class = shift;
43             my %p = validate(
44             \@_,
45             action => { isa => 'Fey.Mock.ORM.ActionType' },
46             class => { isa => 'ClassName' },
47             values => {
48             isa => 'HashRef',
49             optional => 1,
50             },
51             pk => {
52             isa => 'HashRef',
53             optional => 1,
54             },
55             );
56              
57             my $action = delete $p{action};
58              
59             my $real_class = $class . q{::} . ucfirst $action;
60              
61             return $real_class->new( %p, type => $action );
62             }
63              
64             # needs to come after attributes are defined
65             require Fey::ORM::Mock::Action::Insert;
66             require Fey::ORM::Mock::Action::Update;
67             require Fey::ORM::Mock::Action::Delete;
68              
69             no Moose;
70             no Moose::Util::TypeConstraints;
71              
72             __PACKAGE__->meta()->make_immutable();
73              
74             1;
75              
76             # ABSTRACT: Factory and base class for recorded actions
77              
78             __END__
79              
80             =pod
81              
82             =head1 NAME
83              
84             Fey::ORM::Mock::Action - Factory and base class for recorded actions
85              
86             =head1 VERSION
87              
88             version 0.06
89              
90             =head1 DESCRIPTION
91              
92             This class acts as a factory and base class for actions which are
93             recorded by the mocking layer.
94              
95             =head1 METHODS
96              
97             This class provides the following methods:
98              
99             =head2 Fey::ORM::Mock::Action->new_action( ... )
100              
101             This method accepts all the parameters that would be provided to an
102             action subclass, and uses the "type" parameter to determine which
103             subclass to instantiate.
104              
105             You will probably not need to instantiate this class directly, instead
106             just use C<< Fey::ORM::Mock::Recorder->record_action() >>.
107              
108             =head2 $action->class()
109              
110             Returns the associated class for an action.
111              
112             =head2 $action->type()
113              
114             Returns the type for an action, one of "insert", "update", or
115             "delete".
116              
117             =head2 $action->is_insert()
118              
119             =head2 $action->is_update()
120              
121             =head2 $action->is_delete()
122              
123             These are convenience methods for checking an action's type.
124              
125             =head1 AUTHOR
126              
127             Dave Rolsky <autarch@urth.org>
128              
129             =head1 COPYRIGHT AND LICENSE
130              
131             This software is Copyright (c) 2010 by Dave Rolsky.
132              
133             This is free software, licensed under:
134              
135             The Artistic License 2.0 (GPL Compatible)
136              
137             =cut