File Coverage

blib/lib/Perl/Critic/PolicyListing.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition 2 2 100.0
subroutine 8 8 100.0
pod 2 2 100.0
total 38 38 100.0


line stmt bran cond sub pod time code
1             package Perl::Critic::PolicyListing;
2              
3 2     2   2269 use 5.010001;
  2         10  
4 2     2   10 use strict;
  2         5  
  2         50  
5 2     2   13 use warnings;
  2         4  
  2         70  
6              
7 2     2   12 use Perl::Critic::Policy qw();
  2         9  
  2         45  
8              
9 2     2   8 use overload ( q<""> => 'to_string' );
  2         4  
  2         17  
10              
11             our $VERSION = '1.150';
12              
13             #-----------------------------------------------------------------------------
14              
15             sub new {
16 2     2 1 1069 my ($class, %args) = @_;
17              
18 2         8 my $self = bless {}, $class;
19              
20 2   100     12 my $policies = $args{-policies} || [];
21 2         6 $self->{_policies} = [ sort _by_type @{ $policies } ];
  2         37  
22              
23 2         19 return $self;
24             }
25              
26             #-----------------------------------------------------------------------------
27              
28             sub to_string {
29 1     1 1 1016 my ($self) = @_;
30              
31 1         6 Perl::Critic::Policy::set_format( "%s %p [%t]\n" );
32              
33 1         2 return join q{}, map { "$_" } @{ $self->{_policies} };
  145         4505  
  1         4  
34             }
35              
36             #-----------------------------------------------------------------------------
37              
38 144     144   394 sub _by_type { return ref $a cmp ref $b }
39              
40             1;
41              
42             __END__
43              
44             =pod
45              
46             =head1 NAME
47              
48             Perl::Critic::PolicyListing - Display minimal information about Policies.
49              
50              
51             =head1 DESCRIPTION
52              
53             This is a helper class that formats a set of Policy objects for
54             pretty-printing. There are no user-serviceable parts here.
55              
56              
57             =head1 INTERFACE SUPPORT
58              
59             This is considered to be a non-public class. Its interface is subject
60             to change without notice.
61              
62              
63             =head1 CONSTRUCTOR
64              
65             =over
66              
67             =item C<< new( -policies => \@POLICY_OBJECTS ) >>
68              
69             Returns a reference to a new C<Perl::Critic::PolicyListing> object.
70              
71              
72             =back
73              
74              
75             =head1 METHODS
76              
77             =over
78              
79             =item to_string()
80              
81             Returns a string representation of this C<PolicyListing>. See
82             L<"OVERLOADS"> for more information.
83              
84              
85             =back
86              
87              
88             =head1 OVERLOADS
89              
90             When a L<Perl::Critic::PolicyListing|Perl::Critic::PolicyListing> is
91             evaluated in string context, it produces a one-line summary of the
92             default severity, policy name, and default themes for each
93             L<Perl::Critic::Policy|Perl::Critic::Policy> object that was given to
94             the constructor of this C<PolicyListing>.
95              
96              
97             =head1 AUTHOR
98              
99             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
100              
101              
102             =head1 COPYRIGHT
103              
104             Copyright (c) 2005-2023 Imaginative Software Systems.
105              
106             This program is free software; you can redistribute it and/or modify
107             it under the same terms as Perl itself. The full text of this license
108             can be found in the LICENSE file included with this module.
109              
110             =cut
111              
112             # Local Variables:
113             # mode: cperl
114             # cperl-indent-level: 4
115             # fill-column: 78
116             # indent-tabs-mode: nil
117             # c-indentation-style: bsd
118             # End:
119             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :