File Coverage

blib/lib/CMS/Drupal/Modules/MembershipEntity/Membership.pm
Criterion Covered Total %
statement 18 21 85.7
branch 0 2 0.0
condition n/a
subroutine 6 7 85.7
pod n/a
total 24 30 80.0


line stmt bran cond sub pod time code
1             package CMS::Drupal::Modules::MembershipEntity::Membership;
2             $CMS::Drupal::Modules::MembershipEntity::Membership::VERSION = '0.092';
3             # ABSTRACT: Perl interface to a Drupal MembershipEntity membership
4              
5 1     1   4 use strict;
  1         1  
  1         33  
6 1     1   5 use warnings;
  1         1  
  1         34  
7 1     1   23 use 5.010;
  1         2  
  1         30  
8              
9 1     1   3 use Moo;
  1         1  
  1         9  
10 1     1   276 use Types::Standard qw/ :all /;
  1         1  
  1         9  
11 1     1   30720 use Data::Dumper;
  1         6286  
  1         328  
12              
13             has mid => ( is => 'ro', isa => Int, required => 1 );
14             has created => ( is => 'ro', isa => Int, required => 1 );
15             has changed => ( is => 'ro', isa => Int, required => 1 );
16             has uid => ( is => 'ro', isa => Int, required => 1 );
17             has status => ( is => 'ro', isa => Enum[ qw/0 1 2 3/ ], required => 1 );
18             has member_id => ( is => 'ro', isa => Str, required => 1 );
19             has type => ( is => 'ro', isa => Str, required => 1 );
20             has terms => ( is => 'ro', isa => HashRef, required => 1 );
21              
22             sub is_active {
23 0     0     my $self = shift;
24 0 0         $self->{'_is_active'} = $self->{'status'} eq '1' ? 1 : 0;
25 0           return $self->{'_is_active'};
26             }
27              
28             sub has_renewal {
29             my $self = shift;
30             $self->{'_has_renewal'} = 0;
31             foreach my $term ( values $self->{'terms'} ) {
32             $self->{'_has_renewal'}++ if ($term->is_future and $term->is_active);
33             }
34             return $self->{'_has_renewal'};
35             }
36              
37              
38             1; ## return true to end package MembershipEntity::Membership
39              
40             =pod
41              
42             =head1 NAME
43              
44             CMS::Drupal::Modules::MembershipEntity::Membership
45              
46             =head1 VERSION
47              
48             version 0.092
49              
50             =head1 SYNOPSIS
51              
52             use CMS::Drupal::Modules::MembershipEntity::Membership;
53              
54             $mem = CMS::Drupal::Modules::MembershipEntity::Membership->new(
55             'mid' => '1234',
56             'created' => '1234565432',
57             'changed' => '1234567890',
58             'uid' => '5678',
59             'status' => '1',
60             'member_id' => 'my_scheme_0123',
61             'type' => 'my_type',
62             'terms' => \%terms
63             );
64              
65             =head1 USAGE
66              
67             Note: This module does not currently create or edit Memberships.
68              
69             This module is not designed to be called directly, although it can be. This module is called by L, which has a method to retrieve all 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.)
70              
71             =head2 PARAMETERS
72              
73             B Consult the Drupal MembershipEntity documentation for more details.
74              
75             B The B for the Membership. Must be an integer.
76              
77             B The date-and-time the Membership was created. Must be a Unix timestamp.
78              
79             B The date-and-time the Membership was last changed. Must be a Unix timestamp.
80              
81             B The Drupal user ID for the owner of the Membership. Must be an integer.
82              
83             B The status of the Membership. Must be an integer from 0 to 3.
84              
85             B The unique Member ID that Drupal assigns to the Membership. This is separate from the B and the B and can be configured by the Drupal sysadmin to take almost any string-y format.
86              
87             B The Membership type.
88              
89             B A hashref containing a L object for each term belonging to the Membership, keyed by the B (term ID).
90              
91             =head2 METHODS
92              
93             =over 4
94              
95             =item is_active
96              
97             Returns true if the Membership is active, as defined bythe value of the 'status' field in the database record.
98              
99             =item has_renewal
100              
101             Returns true 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.
102              
103             =back
104              
105             =head1 SEE ALSO
106            
107             L
108              
109             L
110              
111             L
112            
113             =cut