line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Toolforge::MixNMatch::Print::Catalog; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
205480
|
use strict; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
70
|
|
4
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
67
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
782
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
18926
|
|
|
3
|
|
|
|
|
77
|
|
7
|
3
|
|
|
3
|
|
1226
|
use Indent; |
|
3
|
|
|
|
|
42614
|
|
|
3
|
|
|
|
|
81
|
|
8
|
3
|
|
|
3
|
|
1113
|
use Toolforge::MixNMatch::Print::User; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
73
|
|
9
|
3
|
|
|
3
|
|
1024
|
use Toolforge::MixNMatch::Print::YearMonth; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
940
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.03; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub print { |
14
|
6
|
|
|
6
|
1
|
5203
|
my ($obj, $opts_hr) = @_; |
15
|
|
|
|
|
|
|
|
16
|
6
|
100
|
|
|
|
16
|
if (! defined $obj) { |
17
|
1
|
|
|
|
|
4
|
err "Object doesn't exist."; |
18
|
|
|
|
|
|
|
} |
19
|
5
|
100
|
|
|
|
23
|
if (! $obj->isa('Toolforge::MixNMatch::Object::Catalog')) { |
20
|
1
|
|
|
|
|
4
|
err "Object isn't 'Toolforge::MixNMatch::Object::Catalog'."; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
4
|
50
|
|
|
|
7
|
if (! defined $opts_hr) { |
24
|
4
|
|
|
|
|
13
|
$opts_hr = { |
25
|
|
|
|
|
|
|
'type' => 1, |
26
|
|
|
|
|
|
|
'count' => 1, |
27
|
|
|
|
|
|
|
'year_months' => 1, |
28
|
|
|
|
|
|
|
'users' => 1, |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my @print = ( |
33
|
|
|
|
|
|
|
$opts_hr->{'type'} ? 'Type: '.$obj->type : (), |
34
|
4
|
50
|
|
|
|
14
|
$opts_hr->{'count'} ? 'Count: '.$obj->count : (), |
|
|
50
|
|
|
|
|
|
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
53
|
my $i; |
38
|
|
|
|
|
|
|
|
39
|
4
|
100
|
66
|
|
|
10
|
if ($opts_hr->{'year_months'} && @{$obj->year_months}) { |
|
4
|
|
|
|
|
8
|
|
40
|
2
|
|
33
|
|
|
23
|
$i //= Indent->new; |
41
|
2
|
|
|
|
|
37
|
push @print, 'Year/months:'; |
42
|
2
|
|
|
|
|
6
|
$i->add; |
43
|
2
|
0
|
|
|
|
14
|
foreach my $year_month (sort { $a->year <=> $b->year || $a->month <=> $b->month } |
|
2
|
|
|
|
|
17
|
|
44
|
2
|
|
|
|
|
5
|
@{$obj->year_months}) { |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
70
|
push @print, $i->get.Toolforge::MixNMatch::Print::YearMonth::print($year_month); |
47
|
|
|
|
|
|
|
} |
48
|
2
|
|
|
|
|
4
|
$i->remove; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
4
|
100
|
66
|
|
|
47
|
if ($opts_hr->{'users'} && @{$obj->users}) { |
|
4
|
|
|
|
|
7
|
|
52
|
2
|
|
66
|
|
|
24
|
$i //= Indent->new; |
53
|
2
|
|
|
|
|
30
|
push @print, 'Users:'; |
54
|
2
|
|
|
|
|
6
|
$i->add; |
55
|
2
|
|
|
|
|
15
|
foreach my $user (reverse sort { $a->count <=> $b->count } @{$obj->users}) { |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
3
|
|
56
|
4
|
|
|
|
|
23
|
push @print, $i->get.Toolforge::MixNMatch::Print::User::print($user); |
57
|
|
|
|
|
|
|
} |
58
|
2
|
|
|
|
|
5
|
$i->remove; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
4
|
50
|
|
|
|
63
|
return wantarray ? @print : (join "\n", @print); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=pod |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=encoding utf8 |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Toolforge::MixNMatch::Print::Catalog - Mix'n'match catalog structure print. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SYNOPSIS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Print::Catalog qw(print); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $print = print($obj); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SUBROUTINES |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 C<print> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $print = print($obj); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Print Toolforge::MixNMatch::Object::Catalog instance to user output. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns string. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 ERRORS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
obj2struct(): |
95
|
|
|
|
|
|
|
Object doesn't exist. |
96
|
|
|
|
|
|
|
Object isn't 'Toolforge::MixNMatch::Object::Catalog'. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 EXAMPLE |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use strict; |
101
|
|
|
|
|
|
|
use warnings; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use Data::Printer; |
104
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Object::Catalog; |
105
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Object::User; |
106
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Object::YearMonth; |
107
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Print::Catalog; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Object. |
110
|
|
|
|
|
|
|
my $obj = Toolforge::MixNMatch::Object::Catalog->new( |
111
|
|
|
|
|
|
|
'count' => 10, |
112
|
|
|
|
|
|
|
'type' => 'Q5', |
113
|
|
|
|
|
|
|
'users' => [ |
114
|
|
|
|
|
|
|
Toolforge::MixNMatch::Object::User->new( |
115
|
|
|
|
|
|
|
'count' => 6, |
116
|
|
|
|
|
|
|
'uid' => 1, |
117
|
|
|
|
|
|
|
'username' => 'Skim', |
118
|
|
|
|
|
|
|
), |
119
|
|
|
|
|
|
|
Toolforge::MixNMatch::Object::User->new( |
120
|
|
|
|
|
|
|
'count' => 4, |
121
|
|
|
|
|
|
|
'uid' => 2, |
122
|
|
|
|
|
|
|
'username' => 'Foo', |
123
|
|
|
|
|
|
|
), |
124
|
|
|
|
|
|
|
], |
125
|
|
|
|
|
|
|
'year_months' => [ |
126
|
|
|
|
|
|
|
Toolforge::MixNMatch::Object::YearMonth->new( |
127
|
|
|
|
|
|
|
'count' => 2, |
128
|
|
|
|
|
|
|
'month' => 9, |
129
|
|
|
|
|
|
|
'year' => 2020, |
130
|
|
|
|
|
|
|
), |
131
|
|
|
|
|
|
|
Toolforge::MixNMatch::Object::YearMonth->new( |
132
|
|
|
|
|
|
|
'count' => 8, |
133
|
|
|
|
|
|
|
'month' => 10, |
134
|
|
|
|
|
|
|
'year' => 2020, |
135
|
|
|
|
|
|
|
), |
136
|
|
|
|
|
|
|
], |
137
|
|
|
|
|
|
|
); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Print. |
140
|
|
|
|
|
|
|
print Toolforge::MixNMatch::Print::Catalog::print($obj)."\n"; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Output: |
143
|
|
|
|
|
|
|
# Type: Q5 |
144
|
|
|
|
|
|
|
# Count: 10 |
145
|
|
|
|
|
|
|
# Year/months: |
146
|
|
|
|
|
|
|
# 2020/9: 2 |
147
|
|
|
|
|
|
|
# 2020/10: 8 |
148
|
|
|
|
|
|
|
# Users: |
149
|
|
|
|
|
|
|
# Skim (1): 6 |
150
|
|
|
|
|
|
|
# Foo (2): 4 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L<Error::Pure>. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SEE ALSO |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item L<Toolforge::MixNMatch::Print> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Toolforge Mix'n'match tool object print routines. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=back |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 REPOSITORY |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Toolforge-MixNMatch-Print> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 AUTHOR |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L<http://skim.cz> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
© Michal Josef Špaček 2020 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
BSD 2-Clause License |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 VERSION |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
0.05 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |