File Coverage

blib/lib/WWW/Suffit/AuthDB/Group.pm
Criterion Covered Total %
statement 17 25 68.0
branch 3 6 50.0
condition 2 9 22.2
subroutine 5 6 83.3
pod 2 2 100.0
total 29 48 60.4


line stmt bran cond sub pod time code
1             package WWW::Suffit::AuthDB::Group;
2 3     3   20 use strict;
  3         7  
  3         113  
3 3     3   17 use utf8;
  3         6  
  3         18  
4              
5             =encoding utf8
6              
7             =head1 NAME
8              
9             WWW::Suffit::AuthDB::Group - WWW::Suffit::AuthDB group class
10              
11             =head1 SYNOPSIS
12              
13             use WWW::Suffit::AuthDB::Group;
14              
15             =head1 DESCRIPTION
16              
17             This module provides AuthDB group methods
18              
19             =head1 ATTRIBUTES
20              
21             This class implements the following attributes
22              
23             =head2 cached
24              
25             $group = $group->cached( 12345.123456789 );
26             my $cached = $group->cached;
27              
28             Sets or returns time of caching group data
29              
30             Default: 0
31              
32             =head2 cachekey
33              
34             $group = $group->cachekey( 'abcdef1234567890' );
35             my $cachekey = $group->cachekey;
36              
37             Sets or returns the cache key string
38              
39             =head2 description
40              
41             $group->description('Root group');
42             my $description = $group->description;
43              
44             Sets and returns description of the group
45              
46             =head2 error
47              
48             $group = $group->error( 'Oops' );
49             my $error = $group->error;
50              
51             Sets or returns error string
52              
53             =head2 expires
54              
55             $group = $group->expires( 300 );
56             my $expires = $group->expires;
57              
58             Sets or returns cache/object expiration time in seconds
59              
60             Default: 300 (5 min)
61              
62             =head2 groupname
63              
64             $group->groupname('wheel');
65             my $groupname = $group->groupname;
66              
67             Sets and returns groupname of the group
68              
69             =head2 id
70              
71             $group = $group->id( 2 );
72             my $id = $group->id;
73              
74             Sets or returns id of group
75              
76             Default: 0
77              
78             =head2 is_cached
79              
80             This attribute returns true if the group data was cached
81              
82             Default: false
83              
84             =head2 users
85              
86             $group->users([qw/ alice bob /]);
87             my $users = $group->users; # ['alice', 'bob']
88              
89             Sets and returns users of group (array of users)
90              
91             =head1 METHODS
92              
93             This class inherits all methods from L and implements the following new ones
94              
95             =head2 is_valid
96              
97             $group->is_valid or die "Incorrect group";
98              
99             Returns boolean status of group's data
100              
101             =head2 mark
102              
103             Marks object as cached
104              
105             =head1 HISTORY
106              
107             See C file
108              
109             =head1 TO DO
110              
111             See C file
112              
113             =head1 SEE ALSO
114              
115             L, L
116              
117             =head1 AUTHOR
118              
119             Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE
120              
121             =head1 COPYRIGHT
122              
123             Copyright (C) 1998-2026 D&D Corporation
124              
125             =head1 LICENSE
126              
127             This program is distributed under the terms of the Artistic License Version 2.0
128              
129             See the C file or L for details
130              
131             =cut
132              
133 3     3   182 use Mojo::Base -base;
  3         5  
  3         36  
134              
135 3     3   988 use Mojo::Util qw/steady_time/;
  3         7  
  3         1907  
136              
137             has description => '';
138             has error => '';
139             has expires => 0;
140             has groupname => undef;
141             has id => 0;
142             has users => sub { return [] };
143             has is_cached => 0; # 0 or 1
144             has cached => 0; # steady_time() of cached
145             has cachekey => '';
146              
147             sub is_valid {
148 1     1 1 14 my $self = shift;
149              
150 1 50       4 unless ($self->id) {
151 0         0 $self->error("E1314: Group not found");
152 0         0 return 0;
153             }
154 1 50 33     9 unless (defined($self->groupname) && length($self->groupname)) {
155 0         0 $self->error("E1315: Incorrect groupname stored");
156 0         0 return 0;
157             }
158 1 50 33     11 if ($self->expires && $self->expires < time) {
159 0         0 $self->error("E1316: The group data is expired");
160 0         0 return 0;
161             }
162              
163 1         8 return 1;
164             }
165              
166             sub mark {
167 0     0 1   my $self = shift;
168 0   0       return $self->is_cached(1)->cached(shift || steady_time);
169             }
170              
171             1;
172              
173             __END__