File Coverage

blib/lib/CPANTS/Kwalitee/Report/Indicator.pm
Criterion Covered Total %
statement 17 49 34.6
branch 0 14 0.0
condition 0 10 0.0
subroutine 6 14 42.8
pod 5 6 83.3
total 28 93 30.1


line stmt bran cond sub pod time code
1             package CPANTS::Kwalitee::Report::Indicator;
2              
3             $CPANTS::Kwalitee::Report::Indicator::VERSION = '0.09';
4             $CPANTS::Kwalitee::Report::Indicator::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             CPANTS::Kwalitee::Report::Indicator - Interface to Kwalitee Indicator.
9              
10             =head1 VERSION
11              
12             Version 0.09
13              
14             =cut
15              
16 3     3   70 use 5.006;
  3         13  
17 3     3   18 use Data::Dumper;
  3         8  
  3         200  
18 3     3   21 use List::Util qw(any);
  3         7  
  3         187  
19              
20 3     3   62 use Moo;
  3         8  
  3         21  
21 3     3   8596 use namespace::clean;
  3         9  
  3         30  
22              
23 3     3   964 use overload q{""} => 'as_string', fallback => 1;
  3         12  
  3         28  
24              
25             has 'name' => (is => 'ro', required => 1);
26             has 'types' => (is => 'ro');
27             has 'error' => (is => 'ro');
28             has 'remedy' => (is => 'ro');
29             has 'verbose' => (is => 'rw', default => sub { 0 });
30              
31             =head1 DESCRIPTION
32              
33             It represents Kwalitee Indicator.
34              
35             =head1 SYNOPSIS
36              
37             use strict; use warnings;
38             use CPANTS::Kwalitee::Report;
39              
40             my $report = CPANTS::Kwalitee::Report->new;
41             my $generators = $report->generators;
42             my $indicators = $generators->[0]->indicators;
43              
44             print sprintf("Name : %s\n", $indicators->[0]->name);
45             print sprintf("Description: %s\n", $indicators->[0]->description);
46              
47             =head1 METHODS
48              
49             =head2 name()
50              
51             Returns indicator name.
52              
53             =head2 description()
54              
55             Returns indicator name with types.
56              
57             =cut
58              
59             sub description {
60 0     0 1   my ($self) = @_;
61              
62 0           my $types = $self->types;
63 0 0         if (scalar(@$types)) {
64 0           return sprintf("%s (%s)", $self->name, join(", ", @$types));
65             }
66             else {
67 0           return $self->name;
68             }
69             }
70              
71             =head2 category()
72              
73             Returns the indicator's category i.e core, optional or experimental.
74              
75             =cut
76              
77             sub category {
78 0     0 1   my ($self) = @_;
79              
80 0 0         if ($self->is_optional) {
    0          
81 0           return 'optional';
82             }
83             elsif ($self->is_experimental) {
84 0           return 'experimental';
85             }
86             else {
87 0           return 'core';
88             }
89             }
90              
91             =head2 is_core()
92              
93             Returns true/false depending if the indicator is core.
94              
95             =cut
96              
97             sub is_core {
98 0     0 1   my ($self) = @_;
99              
100 0   0       return (!$self->is_optional && !$self->is_experimental);
101             }
102              
103             =head2 is_optional()
104              
105             Returns true/false depending if the indicator is optional.
106              
107             =cut
108              
109             sub is_optional {
110 0     0 1   my ($self) = @_;
111              
112 0     0     return any { /is_extra/ } @{$self->types};
  0            
  0            
113             }
114              
115             =head2 is_experimental()
116              
117             Returns true/false depending if the indicator is experimental.
118              
119             =cut
120              
121             sub is_experimental {
122 0     0 1   my ($self) = @_;
123              
124 0     0     return any { /is_experimental/ } @{$self->types};
  0            
  0            
125             }
126              
127             =head2 types()
128              
129             Returns an array ref of indiator types like below:
130              
131             =over 4
132              
133             =item * is_extra
134              
135             =item * is_experimental
136              
137             =item * needs_db
138              
139             =back
140              
141             =head2 error()
142              
143             Returns indicator error string.
144              
145             =head2 remedy()
146              
147             Returns indicator error remedy.
148              
149             =cut
150              
151             sub as_string {
152 0     0 0   my ($self) = @_;
153              
154 0           my $description = $self->description;
155 0   0       my $error = $self->error || 'N/A';
156 0   0       my $remedy = $self->remedy || 'N/A';
157 0           my $verbose = $self->verbose;
158              
159 0 0         if ($verbose) {
160 0 0 0       if (defined $error && defined $remedy) {
161 0           return sprintf("%s\n error: %s\n remedy: %s", $description, $error, $remedy);
162             }
163             else {
164 0 0         if (defined $error) {
    0          
165 0           return sprintf("%s\n error: %s", $description, $error);
166             }
167             elsif (defined $remedy) {
168 0           return sprintf("%s\n remedy: %s", $description, $remedy);
169             }
170             }
171             }
172             else {
173 0           return $description;
174             }
175             }
176              
177             =head1 AUTHOR
178              
179             Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
180              
181             =head1 REPOSITORY
182              
183             L<https://github.com/manwar/CPANTS-Kwalitee-Report>
184              
185             =head1 BUGS
186              
187             Please report any bugs or feature requests to C<bug-cpants-kwalitee-report at rt.cpan.org>,
188             or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPANTS-Kwalitee-Report>.
189             I will be notified and then you'll automatically be notified of progress on your
190             bug as I make changes.
191              
192             =head1 SUPPORT
193              
194             You can find documentation for this module with the perldoc command.
195              
196             perldoc CPANTS::Kwalitee::Report::Indicator
197              
198             You can also look for information at:
199              
200             =over 4
201              
202             =item * RT: CPAN's request tracker (report bugs here)
203              
204             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CPANTS-Kwalitee-Report>
205              
206             =item * AnnoCPAN: Annotated CPAN documentation
207              
208             L<http://annocpan.org/dist/CPANTS-Kwalitee-Report>
209              
210             =item * CPAN Ratings
211              
212             L<http://cpanratings.perl.org/d/CPANTS-Kwalitee-Report>
213              
214             =item * Search CPAN
215              
216             L<http://search.cpan.org/dist/CPANTS-Kwalitee-Report/>
217              
218             =back
219              
220             =head1 LICENSE AND COPYRIGHT
221              
222             Copyright (C) 2017 Mohammad S Anwar.
223              
224             This program is free software; you can redistribute it and / or modify it under
225             the terms of the the Artistic License (2.0). You may obtain a copy of the full
226             license at:
227              
228             L<http://www.perlfoundation.org/artistic_license_2_0>
229              
230             Any use, modification, and distribution of the Standard or Modified Versions is
231             governed by this Artistic License.By using, modifying or distributing the Package,
232             you accept this license. Do not use, modify, or distribute the Package, if you do
233             not accept this license.
234              
235             If your Modified Version has been derived from a Modified Version made by someone
236             other than you,you are nevertheless required to ensure that your Modified Version
237             complies with the requirements of this license.
238              
239             This license does not grant you the right to use any trademark, service mark,
240             tradename, or logo of the Copyright Holder.
241              
242             This license includes the non-exclusive, worldwide, free-of-charge patent license
243             to make, have made, use, offer to sell, sell, import and otherwise transfer the
244             Package with respect to any patent claims licensable by the Copyright Holder that
245             are necessarily infringed by the Package. If you institute patent litigation
246             (including a cross-claim or counterclaim) against any party alleging that the
247             Package constitutes direct or contributory patent infringement,then this Artistic
248             License to you shall terminate on the date that such litigation is filed.
249              
250             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
251             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
252             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
253             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
254             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
255             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
256             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
257              
258             =cut
259              
260             1; # End of CPANTS::Kwalitee::Report::Indicator