lib/CMS/Drupal/Modules/MembershipEntity/Membership.pm

filter: Statementstmt 100% 46 / 46 Branchbran 75.0% 9 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 91.6% 77 / 84 CC 11 SCAR 9.8
CC
11
Cov
92%
current_was_renewal
4.3
has_renewal
4.0
is_cancelled
2.0
CRAP 2.7
« lib/CMS/Drupal/Modules/MembershipEntity/Test.pm ↑ Summary lib/CMS/Drupal/Modules/MembershipEntity/Term.pm »
1 package CMS::Drupal::Modules::MembershipEntity::Membership;
2 10 $CMS::Drupal::Modules::MembershipEntity::Membership::VERSION = '0.96';
3 # ABSTRACT: Perl interface to a Drupal MembershipEntity membership
4  
5 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Types::Standard qw/ :all /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 has mid => ( is => 'ro', isa => Int, required => 1 );
12 10 has created => ( is => 'ro', isa => Int, required => 1 );
13 10 has changed => ( is => 'ro', isa => Int, required => 1 );
14 10 has uid => ( is => 'ro', isa => Int, required => 1 );
15 10 has status => ( is => 'ro', isa => Enum[ qw/0 1 2 3/ ], required => 1 );
16 10 has member_id => ( is => 'ro', isa => Str, required => 1 );
17 10 has type => ( is => 'ro', isa => Str, required => 1 );
18 10 has terms => ( is => 'ro', isa => HashRef, required => 1 );
19  
20  
21 sub is_expired {
22 29 ▶ my $self = shift;
Subroutine is_expired: called CC=2 SCAR=6.9
Pod documented
23 29 ▶ $self->{'_is_expired'} = $self->{'status'} eq '0' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'status'} eq '0' ? : 13 16 29
24 29 return $self->{'_is_expired'};
25 }
26  
27  
28 sub is_active {
29 33 ▶ my $self = shift;
Subroutine is_active: called CC=2 SCAR=6.9
Pod documented
30 33 ▶ $self->{'_is_active'} = $self->{'status'} eq '1' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'status'} eq '1' ? : 17 16 33
31 33 return $self->{'_is_active'};
32 }
33  
34  
35 sub is_cancelled {
36 29 ▶ my $self = shift;
Subroutine is_cancelled: called CC=2 SCAR=7.1
Pod documented
37 29 ▶ $self->{'_is_cancelled'} = $self->{'status'} eq '2' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'status'} eq '2' ? : 0 29 29
38 29 return $self->{'_is_cancelled'};
39 }
40  
41  
42 sub is_pending {
43 29 ▶ my $self = shift;
Subroutine is_pending: called CC=2 SCAR=7.1
Pod documented
44 29 ▶ $self->{'_is_pending'} = $self->{'status'} eq '3' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'status'} eq '3' ? : 0 29 29
45 29 return $self->{'_is_pending'};
46 }
47  
48  
49 sub has_renewal {
50 3 ▶ my $self = shift;
Subroutine has_renewal: called CC=4 SCAR=13.9
Pod documented
51 3 $self->{'_has_renewal'} = 0;
52 3 foreach my $term ( values %{ $self->{'terms'} } ) {
53 5 ▶ $self->{'_has_renewal'} = 1 if ($term->is_future and $term->is_active);
Branch: 1 branch
BranchTrueFalseTotal
if $term->is_future and $term->is_active 1 4 5
Condition100%3/3
$term->is_future and $term->is_active
!ll&&!rl&&r
311
MC/DC100%2/2
$term->is_future and $term->is_active
$term->is_future $term->is_active
Truth table100%3/3
A and B
A= $term->is_futureB= $term->is_active
ABresult
0X0
100
111
54 }
55 3 return $self->{'_has_renewal'};
56 }
57  
58  
59 sub current_was_renewal {
60 29 ▶ my $self = shift;
Subroutine current_was_renewal: called CC=4 SCAR=14.6
Pod documented
61 29 $self->{'_current_was_renewal'} = 0;
62 29 foreach my $term ( values %{ $self->{'terms'} } ) {
63 33 ▶ $self->{'_current_was_renewal'} = 1 if ($term->is_current and $term->was_renewal);
Branch: 1 branch
BranchTrueFalseTotal
if $term->is_current and $term->was_renewal 0 33 33
Condition33%1/3
$term->is_current and $term->was_renewal
!ll&&!rl&&r
3300
MC/DC0%0/2
$term->is_current and $term->was_renewal
$term->is_current $term->was_renewal
Truth table33%1/3
A and B
A= $term->is_currentB= $term->was_renewal
ABresult
0X0
100
111
64 }
65 29 return $self->{'_current_was_renewal'};
66 }
67  
68  
69 10 1; ## return true to end package MembershipEntity::Membership
70  
71 __END__
72  
73 =pod
74  
75 =encoding UTF-8
76  
77 =head1 NAME
78  
79 CMS::Drupal::Modules::MembershipEntity::Membership - Perl interface to a Drupal MembershipEntity membership
80  
81 =head1 VERSION
82  
83 version 0.96
84  
85 =head1 SYNOPSIS
86  
87 use CMS::Drupal::Modules::MembershipEntity::Membership;
88  
89 $mem = CMS::Drupal::Modules::MembershipEntity::Membership->new(
90 'mid' => '1234',
91 'created' => '1234565432',
92 'changed' => '1234567890',
93 'uid' => '5678',
94 'status' => '1',
95 'member_id' => 'my_scheme_0123',
96 'type' => 'my_type',
97 'terms' => \%terms
98 );
99  
100 =head1 METHODS
101  
102 =head2 is_expired
103  
104 Returns 1 if the Membership has status of 'expired'. Else returns 0.
105  
106 =head2 is_active
107  
108 Returns 1 if the Membership has status of 'active'. Else returns 0.
109  
110 =head2 is_cancelled
111  
112 Returns 1 if the Membership has status of 'cancelled'. Else returns 0.
113  
114 =head2 is_pending
115  
116 Returns 1 if the Membership has status of 'pending'. Else returns 0.
117  
118 =head2 has_renewal
119  
120 Returns 1 if the Membership has a renewal Term that has not yet started. This is defined by the value of $term->is_future and $term->is_active both being true for at least one of the Membership's Terms. Else returns 0.
121  
122 print "User $mem->{'uid'} has already renewed" if $mem->has_renewal;
123  
124 =head2 current_was_renewal
125  
126 Returns 1 if the current Term belonging to the Membership was a renewal
127 (i.e. not the Membership's first ever Term). Else returns 0.
128  
129 =head1 USAGE
130  
131 Note: This module does not currently create or edit Memberships.
132  
133 This module is not designed to be called directly, although it can be. This module is called by L<CMS::Drupal::Modules::MembershipEntity|CMS::Drupal::Modules::MembershipEntity>, which has a method to retrieve Memberships and create an object for each of them. Error checking is handled in the latter module, so if you use this module directly you will have to do your own error checking, for example, to make sure that the Membership actually has at least one Term associated with it. (Yes, I know it should be impossible not to, but it happens. This is Drupal we are dealing with.)
134  
135 =head2 CONSTRUCTOR PARAMETERS
136  
137 B<All parameters are required.> Consult the Drupal MembershipEntity documentation for more details.
138  
139 =over 4
140  
141 =item *
142  
143 B<mid>
144  
145 The B<mid> for the Membership. Must be an integer.
146  
147 =item *
148  
149 B<created>
150  
151 The date-and-time the Membership was created. Must be a Unix timestamp.
152  
153 =item *
154  
155 B<changed>
156  
157 The date-and-time the Membership was last changed. Must be a Unix timestamp.
158  
159 =item *
160  
161 B<uid>
162  
163 The Drupal user ID for the owner of the Membership. Must be an integer.
164  
165 =item *
166  
167 B<status>
168  
169 The status of the Membership. Must be an integer from 0 to 3.
170  
171 =item *
172  
173 B<member_id>
174  
175 The unique Member ID that Drupal assigns to the Membership. This is separate from the B<uid> and the B<mid> and can be configured by the Drupal sysadmin to take almost any string-y format.
176  
177 =item *
178  
179 B<type>
180  
181 The Membership type.
182  
183 =item *
184  
185 B<terms>
186  
187 A hashref containing a L<CMS::Drupal::Modules::MembershipEntity::Term|CMS::Drupal::Modules::MembershipEntity::Term> object for each term belonging to the Membership, keyed by the B<tid> (term ID).
188  
189 =back
190  
191 =head1 SEE ALSO
192  
193 =over 4
194  
195 =item *
196  
197 L<CMS::Drupal|CMS::Drupal>
198  
199 =item *
200  
201 L<CMS::Drupal::Modules::MembershipEntity|CMS::Drupal::Modules::MembershipEntity>
202  
203 =item *
204  
205 L<CMS::Drupal::Modules::MembershipEntity::Term|CMS::Drupal::Modules::MembershipEntity::Term>
206  
207 =back
208  
209 =head1 AUTHOR
210  
211 Nick Tonkin <tonkin@cpan.org>
212  
213 =head1 COPYRIGHT AND LICENSE
214  
215 This software is copyright (c) 2015 by Nick Tonkin.
216  
217 This is free software; you can redistribute it and/or modify it under
218 the same terms as the Perl 5 programming language system itself.
219  
220 =cut
« lib/CMS/Drupal/Modules/MembershipEntity/Test.pm ↑ Summary lib/CMS/Drupal/Modules/MembershipEntity/Term.pm »