File Coverage

blib/lib/Toolforge/MixNMatch/Object/Catalog.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 27 28 96.4


line stmt bran cond sub pod time code
1             package Toolforge::MixNMatch::Object::Catalog;
2              
3 3     3   496849 use strict;
  3         8  
  3         106  
4 3     3   16 use warnings;
  3         6  
  3         163  
5              
6 3     3   2592 use Mo qw(build default is);
  3         1943  
  3         18  
7 3     3   11145 use Mo::utils qw(check_required);
  3         41537  
  3         83  
8 3     3   2114 use Mo::utils::Array qw(check_array_object);
  3         7607  
  3         69  
9              
10             our $VERSION = 0.04;
11              
12             has count => (
13             is => 'ro',
14             );
15              
16             has type => (
17             is => 'ro',
18             );
19              
20             has year_months => (
21             default => [],
22             is => 'ro',
23             );
24              
25             has users => (
26             default => [],
27             is => 'ro',
28             );
29              
30             sub BUILD {
31 3     3 0 239077 my $self = shift;
32              
33             # Check require.
34 3         22 check_required($self, 'count');
35 2         26 check_required($self, 'type');
36              
37             # Check year month.
38 1         14 check_array_object($self, 'year_months', 'Toolforge::MixNMatch::Object::YearMonth');
39              
40             # Check users.
41 1         11 check_array_object($self, 'users', 'Toolforge::MixNMatch::Object::User');
42              
43 1         8 return;
44             }
45              
46             1;
47              
48             __END__
49              
50             =pod
51              
52             =encoding utf8
53              
54             =head1 NAME
55              
56             Toolforge::MixNMatch::Object::Catalog - Mix'n'match catalog datatype.
57              
58             =head1 SYNOPSIS
59              
60             use Toolforge::MixNMatch::Object::Catalog;
61              
62             my $obj = Toolforge::MixNMatch::Object::Catalog->new(%params);
63             my $count = $obj->count;
64             my $type = $obj->type;
65             my $year_months = $obj->year_months;
66             my $users = $obj->users;
67              
68             =head1 DESCRIPTION
69              
70             This datatype is base class for Mix'n'match catalog.
71              
72             =head1 METHODS
73              
74             =head2 C<new>
75              
76             my $obj = Toolforge::MixNMatch::Object::Catalog->new(%params);
77              
78             Constructor.
79              
80             Returns instance of object.
81              
82             =over 8
83              
84             =item * C<count>
85              
86             Count number of records in catalog.
87             Parameter is required.
88              
89             =item * C<type>
90              
91             Catalog type in sense of Wikidata instance.
92             Example is 'Q5' for human.
93             Parameter is required.
94              
95             =item * C<year_months>
96              
97             Year/months statistics.
98             Reference to array with Toolforge::MixNMatch::Object::YearMonth instances.
99             Default value is [].
100              
101             =item * C<users>
102              
103             Users statistics.
104             Reference to array with Toolforge::MixNMatch::Object::User instances.
105             Default value is [].
106              
107             =back
108              
109             =head2 C<count>
110              
111             my $count = $obj->count;
112              
113             Get count.
114              
115             Returns number.
116              
117             =head2 C<type>
118              
119             my $type = $obj->type;
120              
121             Get type.
122              
123             Returns string.
124              
125             =head2 C<year_months>
126              
127             my $year_months = $obj->year_months;
128              
129             Get year/months statistics.
130              
131             Returns reference to array with Toolforge::MixNMatch::Object::YearMonth
132             instances.
133              
134             =head2 C<users>
135              
136             my $users = $obj->users;
137              
138             Get users statistics.
139              
140             Returns reference to array with Toolforge::MixNMatch::Object::User
141             instances.
142              
143             =head1 ERRORS
144              
145             new():
146             From Mo::utils::check_required():
147             Parameter 'count' is required.
148             Parameter 'type' is required.
149              
150             From Mo::utils::Array::check_array_object():
151             Parameter 'users' must be a array.
152             Value: %s
153             Reference: %s
154             Parameter 'users' with array must contain 'Toolforge::MixNMatch::Object::Catalog::User' objects.
155             Value: %s
156             Reference: %s
157             Parameter 'year_months' must be a array.
158             Value: %s
159             Reference: %s
160             Parameter 'year_months' with array must contain 'Toolforge::MixNMatch::Object::Catalog::YearMonth' objects.
161             Value: %s
162             Reference: %s
163              
164             =head1 EXAMPLE
165              
166             =for comment filename=create_catalog_and_print_out.pl
167              
168             use strict;
169             use warnings;
170              
171             use Toolforge::MixNMatch::Object::Catalog;
172             use Toolforge::MixNMatch::Object::User;
173             use Toolforge::MixNMatch::Object::YearMonth;
174              
175             # Object.
176             my $obj = Toolforge::MixNMatch::Object::Catalog->new(
177             'count' => 10,
178             'type' => 'Q5',
179             'users' => [
180             Toolforge::MixNMatch::Object::User->new(
181             'count' => 6,
182             'uid' => 1,
183             'username' => 'Skim',
184             ),
185             Toolforge::MixNMatch::Object::User->new(
186             'count' => 4,
187             'uid' => 2,
188             'username' => 'Foo',
189             ),
190             ],
191             'year_months' => [
192             Toolforge::MixNMatch::Object::YearMonth->new(
193             'count' => 2,
194             'month' => 9,
195             'year' => 2020,
196             ),
197             Toolforge::MixNMatch::Object::YearMonth->new(
198             'count' => 8,
199             'month' => 10,
200             'year' => 2020,
201             ),
202             ],
203             );
204              
205             # Get count.
206             my $count = $obj->count;
207              
208             # Get type.
209             my $type = $obj->type;
210              
211             # Get year months stats.
212             my $year_months_ar = $obj->year_months;
213              
214             # Get users.
215             my $users_ar = $obj->users;
216              
217             # Print out.
218             print "Count: $count\n";
219             print "Type: $type\n";
220             print "Number of month/year statistics: ".(scalar @{$year_months_ar})."\n";
221             print "Number of users: ".(scalar @{$users_ar})."\n";
222              
223             # Output:
224             # Count: 10
225             # Type: Q5
226             # Number of month/year statistics: 2
227             # Number of users: 2
228              
229             =head1 DEPENDENCIES
230              
231             L<Mo>,
232             L<Mo::utils>,
233             L<Mo::utils::Array>.
234              
235             =head1 SEE ALSO
236              
237             =over
238              
239             =item L<Toolforge::MixNMatch::Object>
240              
241             Toolforge Mix'n'match tool objects.
242              
243             =back
244              
245             =head1 REPOSITORY
246              
247             L<https://github.com/michal-josef-spacek/Toolforge-MixNMatch-Object>
248              
249             =head1 AUTHOR
250              
251             Michal Josef Špaček L<mailto:skim@cpan.org>
252              
253             L<http://skim.cz>
254              
255             =head1 LICENSE AND COPYRIGHT
256              
257             © Michal Josef Špaček 2020-2025
258              
259             BSD 2-Clause License
260              
261             =head1 VERSION
262              
263             0.04
264              
265             =cut