lib/Reaction/InterfaceModel/Collection/DBIC/Role/Base.pm

filter: Statementstmt 51.5% 17 / 33 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 41.6% 5 / 12 Podpod 66.6% 4 / 6 totaltotal 46.4% 26 / 56 CC 2 SCAR 8.0
CC
2
Cov
47%
_build_member_type
6.0
clone
2.0
count_members
2.0
CRAP 2.2
« lib/Reaction/Types/Core.pm ↑ Summary lib/Reaction/UI/Controller/Role/Action/Simple.pm »
1 package Reaction::InterfaceModel::Collection::DBIC::Role::Base;
2  
3 5 ▶use Reaction::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # WARNING - DANGER: this is just an RFC, please DO NOT USE YET
8  
9 5 ▶use namespace::clean -except => [ qw(meta) ];
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 5 has '_source_resultset' => (
13 is => 'ro',
14 required => 1,
15 isa => 'DBIx::Class::ResultSet',
16 );
17  
18 5 has 'member_type' => (
19 is => 'rw',
20 isa => 'ClassName',
21 required => 1,
22 builder => '_build_member_type',
23 clearer => 'clear_member_type',
24 predicate => 'has_member_type',
25 );
26  
27  
28 #implements BUILD => as {
29 # my $self = shift;
30 # Class::MOP::load_class($self->_im_class);
31 # confess "_im_result_class must be a Reaction::InterfaceModel::Object"
32 # unless $self->_im_class->isa("Reaction::InterfaceModel::Object");
33 # confess "_im_result_class must have an inflate_result method"
34 # unless $self->_im_class->can("inflate_result");
35 #};
36  
37  
38  
39 #Oh man. I have a bad feeling about this one.
40 0 ▶sub _build_member_type {
Subroutine _build_member_type: not called CC=2 SCAR=17.9
41 0 my $self = shift;
42 0 ▶ my $class = blessed($self) || $self;
Condition0%0/3
builtin::blessed($self) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self) $self
Truth table0%0/3
A || B
A= builtin::blessed($self)B= $self
ABresult
1X1
011
000
43 0 $class =~ s/::Collection$//;
44 0 return $class;
45 };
46 3 ▶sub _build__collection_store {
Subroutine _build__collection_store: called CC=1 SCAR=0.0
47 3 my $self = shift;
48 3 [ $self->_source_resultset->search({}, {result_class => $self->member_type})->all ];
49 };
50 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
51 0 my $self = shift;
52 0 my $rs = $self->_source_resultset; #->search_rs({});
53 #should the clone include the arrayref of IM::Objects too?
54 0 return (blessed $self)->new(
55 _source_resultset => $rs,
56 member_type => $self->member_type, @_
57 );
58 };
59 0 ▶sub count_members {
Subroutine count_members: not called CC=1 SCAR=6.9
Pod documented
60 0 my $self = shift;
61 0 $self->_source_resultset->count;
62 };
63 0 ▶sub add_member {
Subroutine add_member: not called CC=1 SCAR=6.9
Pod documented
64 0 confess "Not yet implemented";
65 };
66 0 ▶sub remove_member {
Subroutine remove_member: not called CC=1 SCAR=6.9
Pod documented
67 0 confess "Not yet implemented";
68 };
69 0 ▶sub page {
Subroutine page: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my $self = shift;
71 0 my $rs = $self->_source_resultset->page(@_);
72 0 return (blessed $self)->new(
73 _source_resultset => $rs,
74 member_type => $self->member_type,
75 );
76 };
77 0 ▶sub pager {
Subroutine pager: not called CC=1 SCAR=6.9
Pod undocumented
78 0 my $self = shift;
79 0 return $self->_source_resultset->pager(@_);
80 };
81  
82  
83  
84 5 1;
85  
86  
87 =head1 NAME
88  
89 Reaction::InterfaceModel::Collection::DBIC::Role::Base
90  
91 =head1 DESCRIPTION
92  
93 Provides methods to allow a collection to be populated by a L<DBIx::Class::ResultSet>
94  
95 =head1 Attributes
96  
97 =head2 _source_resultset
98  
99 Required, Read-only. Contains the L<DBIx::Class::ResultSet> used to populate the
100 collection.
101  
102 =head2 member_type
103  
104 Read-only, lazy_build. The name of the IM Object Class that the resultset inside this
105 collection will inflate to. Predicate: C<has_member_type>
106  
107 =head1 METHODS
108  
109 =head2 clone
110  
111 Returns a clone of the current collection, complete with a cloned C<_source_resultset>
112  
113 =head2 count_members
114  
115 Returns the number of items found by the ResultSet
116  
117 =head2 add_member
118  
119 =head2 remove_member
120  
121 These will die as they have not been implemented yet.
122  
123 =head1 PRIVATE METHODS
124  
125 =head2 _build_im_class
126  
127 Will attempt to remove the suffix "Collection" from the current class name and return
128 that. I.e. C<MyApp::MyIM::Roles::Collection> would return C<MyApp::MyIM::Roles>
129  
130 =head2 _build_collection_store
131  
132 Replace the default builder to populate the collection with all results returned by the
133 resultset.
134  
135 =head1 AUTHORS
136  
137 See L<Reaction::Class> for authors.
138  
139 =head1 LICENSE
140  
141 See L<Reaction::Class> for the license.
142  
143 =cut
« lib/Reaction/Types/Core.pm ↑ Summary lib/Reaction/UI/Controller/Role/Action/Simple.pm »