« lib/CMS/Drupal/Modules/MembershipEntity/Membership.pm
↑ Summary
lib/CMS/Drupal/Modules/MembershipEntity/Cookbook.pm »
| 1 | package CMS::Drupal::Modules::MembershipEntity::Term; | ||||||||||||||||||||||||||||
| 2 | 10 | $CMS::Drupal::Modules::MembershipEntity::Term::VERSION = '0.96'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Perl interface to a Drupal MembershipEntity membership term | ||||||||||||||||||||||||||||
| 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 tid => ( is => 'ro', isa => Int, required => 1 ); | |||||||||||||||||||||||||||
| 12 | 10 | has mid => ( is => 'ro', isa => Int, required => 1 ); | |||||||||||||||||||||||||||
| 13 | 10 | has status => ( is => 'ro', isa => Int, required => 1 ); | |||||||||||||||||||||||||||
| 14 | 10 | has term => ( is => 'ro', isa => Str, required => 1 ); | |||||||||||||||||||||||||||
| 15 | 10 | has modifiers => ( is => 'ro', isa => Str, required => 1 ); | |||||||||||||||||||||||||||
| 16 | 10 | has start => ( is => 'ro', isa => Int, required => 1 ); | |||||||||||||||||||||||||||
| 17 | 10 | has end => ( is => 'ro', isa => Int, required => 1 ); | |||||||||||||||||||||||||||
| 18 | 10 | has array_position => ( is => 'ro', isa => Int, required => 1 ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub is_active { | ||||||||||||||||||||||||||||
| 21 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_active: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 6 | ▶ | return $self->{'status'} eq '1' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | ? 1 : 0; | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub is_current { | ||||||||||||||||||||||||||||
| 27 | 38 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_current: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 38 | my $now = time; | |||||||||||||||||||||||||||
| 29 | 38 | ▶ | return ( $self->{'start'} <= $now and $self->{'end'} > $now ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"start"} <= $now and $self->{"end"} > $now
MC/DC100%2/2
$self->{"start"} <= $now and $self->{"end"} > $now
$self->{"start"} <= $now
$self->{"end"} > $now
Truth table100%3/3
A and B
A= $self->{"start"} <= $nowB= $self->{"end"} > $now
| |||||||||||||||||||||||||||||
| 30 | ? 1 : 0; | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub is_future { | ||||||||||||||||||||||||||||
| 34 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_future: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 10 | my $now = time; | |||||||||||||||||||||||||||
| 36 | 10 | ▶ | return ($self->{'start'} > $now and $self->{'end'} > $self->{'start'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"start"} > $now and $self->{"end"} > $self->{"start"}
MC/DC100%2/2
$self->{"start"} > $now and $self->{"end"} > $self->{"start"}
$self->{"start"} > $now
$self->{"end"} > $self->{"start"}
Truth table100%3/3
A and B
A= $self->{"start"} > $nowB= $self->{"end"} > $self->{"start"}
| |||||||||||||||||||||||||||||
| 37 | ? 1 : 0; | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub was_renewal { | ||||||||||||||||||||||||||||
| 41 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
was_renewal: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 8 | ▶ | return ($self->{'array_position'} > 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | ? 1 : 0; | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 10 | 1; ## return true to end package MembershipEntity::Term | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | __END__ | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =pod | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 NAME | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | CMS::Drupal::Modules::MembershipEntity::Term - Perl interface to a Drupal MembershipEntity membership term | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head1 VERSION | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | version 0.96 | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | use CMS::Drupal::Modules::MembershipEntity::Term; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | $term = CMS::Drupal::Modules::MembershipEntity::Term->new( | ||||||||||||||||||||||||||||
| 67 | 'tid' => '4321', | ||||||||||||||||||||||||||||
| 68 | 'mid' => '1234', | ||||||||||||||||||||||||||||
| 69 | 'status' => '1', | ||||||||||||||||||||||||||||
| 70 | 'term' => 'One year', | ||||||||||||||||||||||||||||
| 71 | 'modifiers' => 'a:0:{}', | ||||||||||||||||||||||||||||
| 72 | 'start' => '1234567890', | ||||||||||||||||||||||||||||
| 73 | 'end' => '1234568999', | ||||||||||||||||||||||||||||
| 74 | 'array_position' => '2', | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 METHODS | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head2 is_active | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Returns 1 if the Term has a status of 'active.' Note this does not mean it is the current Term (see below). Returns 0 for any other status. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 is_current | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Returns 1 if the Term is the current Term (i.e. the date-and-time now falls between the start date-and-time and the end date-and-time). (Note that the Term may be 'current' but not 'active', eg 'pending'.) Returns 0 otherwise. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head2 is_future | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Returns 1 if the Term has not yet begun (i.e. the start date-and-time is after the current time). Memberships can be renewed before they expire, so a Term can have a status of 'active' but be held in the future. Returns 0 otherwise. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head2 was_renewal | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Returns 1 if the Term was a renewal, as defined by the Term's B<array_position> being greater than 1 (i.e., there was an earlier Term). | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 USAGE | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Note: This module does not currently create or edit Membership Terms. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | This module is not designed to be called directly, although it can be. This module is called by L<CMS::Drupal::Modules::MembershipEntity>, which has a method that retrieves all Membership Terms and creates an object for each of them (which is stored inside the parent Membership object). 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 Term actually has a start and an end date-and-time associated with it. (Yes, I know it should be impossible not to, but it happens. This is Drupal we are dealing with.) | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head2 CONSTRUCTOR PARAMETERS | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | B<All parameters are required.> Consult the Drupal MembershipEntity documentation for more details. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =over 4 | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =item * | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | B<tid> | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | The B<tid> for the Term. Must be an integer. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =item * | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | B<mid> | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | The B<mid> for the parent Membership. Must be an integer. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =item * | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | B<status> | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | The status of the Term. Must be an integer from 0 to 3. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =item * | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | B<modifiers> | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | The special string containing any modifiers to the Term length. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =item * | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | B<start> | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | The start date-and-time for the Term. Must be a Unix timestamp. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =item * | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | B<end> | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | The end date-and-time for the Term. Must be a Unix timestamp. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item * | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | B<array_position> | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | The position the Term holds in the array of Terms belonging to the parent Membership. The array is sorted by start date-and-time ascending, and is indexed from 1, not from zero. (This parameter is passed automatically to this module if you use L<CMS::Drupal::Modules::MembershipEntity>'s B<fetch_memberships()> method.) | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =back | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =over 4 | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =item * | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | L<CMS::Drupal|CMS::Drupal> | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =item * | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | L<CMS::Drupal::Modules::MembershipEntity|CMS::Drupal::Modules::MembershipEntity> | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =item * | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | L<CMS::Drupal::Modules::MembershipEntity::Membership|CMS::Drupal::Modules::MembershipEntity::Membership> | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =back | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | Nick Tonkin <tonkin@cpan.org> | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | This software is copyright (c) 2015 by Nick Tonkin. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 178 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||||||||||