File Coverage

blib/lib/Tags/HTML/CPAN/Changes.pm
Criterion Covered Total %
statement 84 84 100.0
branch 18 18 100.0
condition 9 9 100.0
subroutine 15 15 100.0
pod 1 1 100.0
total 127 127 100.0


line stmt bran cond sub pod time code
1             package Tags::HTML::CPAN::Changes;
2              
3 7     7   1316969 use base qw(Tags::HTML);
  7         16  
  7         4067  
4 7     7   79056 use strict;
  7         17  
  7         243  
5 7     7   40 use warnings;
  7         2014  
  7         449  
6              
7 7     7   41 use Class::Utils qw(set_params split_params);
  7         20  
  7         473  
8 7     7   3761 use CPAN::Version;
  7         12534  
  7         277  
9 7     7   46 use English;
  7         12  
  7         43  
10 7     7   3455 use Error::Pure qw(err);
  7         15  
  7         405  
11 7     7   4669 use Mo::utils 0.01 qw(check_required);
  7         21869  
  7         165  
12 7     7   5297 use Mo::utils::CSS 0.02 qw(check_css_class);
  7         83905  
  7         163  
13 7     7   688 use Scalar::Util qw(blessed);
  7         14  
  7         8590  
14              
15             our $VERSION = 0.06;
16              
17             # Constructor.
18             sub new {
19 30     30 1 2061213 my ($class, @params) = @_;
20              
21             # Create object.
22 30         141 my ($object_params_ar, $other_params_ar) = split_params(
23             ['css_class'], @params);
24 30         786 my $self = $class->SUPER::new(@{$other_params_ar});
  30         151  
25              
26             # CSS class.
27 23         816 $self->{'css_class'} = 'changes';
28              
29             # Process params.
30 23         40 set_params($self, @{$object_params_ar});
  23         67  
31              
32 23         214 check_required($self, 'css_class');
33 22         208 check_css_class($self, 'css_class');
34              
35             # Object.
36 20         556 return $self;
37             }
38              
39             sub _cleanup {
40 1     1   15 my $self = shift;
41              
42 1         11 delete $self->{'_changes'};
43              
44 1         3 return;
45             }
46              
47             sub _init {
48 16     16   29327 my ($self, $changes) = @_;
49              
50 16 100 100     188 if (! defined $changes
      100        
51             || ! blessed($changes)
52             || ! $changes->isa('CPAN::Changes')) {
53              
54 3         45 err "Data object must be a 'CPAN::Changes' instance.";
55             }
56              
57 13 100       234 if (CPAN::Version->vlt($changes->VERSION, '0.500002')) {
58 1         64 err "Minimal version of supported CPAN::Changes is 0.500002.",
59             'Version', $changes->VERSION,
60             ;
61             }
62              
63 12         902 $self->{'_changes'} = $changes;
64              
65 12         37 return;
66             }
67              
68             # Process 'Tags'.
69             sub _process {
70 10     10   131 my $self = shift;
71              
72 10 100       58 if (! exists $self->{'_changes'}) {
73 1         4 return;
74             }
75              
76             $self->{'tags'}->put(
77             ['b', 'div'],
78 9         73 ['a', 'class', $self->{'css_class'}],
79             );
80 9 100       927 if ($self->{'_changes'}->preamble ne '') {
81             $self->{'tags'}->put(
82             ['b', 'h1'],
83 2         17 ['d', $self->{'_changes'}->preamble],
84             ['e', 'h1'],
85             );
86             }
87 9         243 foreach my $changes_rel (sort { $b->version <=> $a->version } $self->{'_changes'}->releases) {
  1         58  
88 8         344 my $version = $changes_rel->version;
89 8 100       32 if (defined $changes_rel->date) {
90 3         26 $version .= ' - '.$changes_rel->date;
91             }
92 8 100       29 if (defined $changes_rel->note) {
93 1         10 $version .= ' '.$changes_rel->note;
94             }
95 8         67 $self->{'tags'}->put(
96             ['b', 'div'],
97             ['a', 'class', 'version'],
98             ['b', 'h2'],
99             ['d', $version],
100             ['e', 'h2'],
101             );
102 8         1389 $self->{'tags'}->put(
103             ['b', 'ul'],
104             ['a', 'class', 'version-changes'],
105             );
106 8         600 foreach my $entry (@{$changes_rel->entries}) {
  8         280  
107 9 100 100     244 if (defined $entry->text && $entry->text ne '') {
108 2 100       3 if (@{$entry->entries}) {
  2         57  
109 1         18 $self->{'tags'}->put(
110             ['b', 'h3'],
111             ['d', '['.$entry->text.']'],
112             ['e', 'h3'],
113             );
114             } else {
115 1         17 $self->{'tags'}->put(
116             ['b', 'li'],
117             ['a', 'class', 'version-change'],
118             ['d', $entry->text],
119             ['e', 'li'],
120             );
121             }
122             }
123 9         242 foreach my $change (@{$entry->entries}) {
  9         215  
124 9         222 $self->{'tags'}->put(
125             ['b', 'li'],
126             ['a', 'class', 'version-change'],
127             ['d', $change->text],
128             ['e', 'li'],
129             );
130             }
131             }
132 8         933 $self->{'tags'}->put(
133             ['e', 'ul'],
134             );
135 8         351 $self->{'tags'}->put(
136             ['e', 'div'],
137             );
138             }
139 9         419 $self->{'tags'}->put(
140             ['e', 'div'],
141             );
142              
143 9         396 return;
144             }
145              
146             sub _process_css {
147 3     3   56 my $self = shift;
148              
149 3 100       22 if (! exists $self->{'_changes'}) {
150 1         3 return;
151             }
152              
153             $self->{'css'}->put(
154             ['s', '.'.$self->{'css_class'}],
155             ['d', 'max-width', '800px'],
156             ['d', 'margin', 'auto'],
157             ['d', 'background', '#fff'],
158             ['d', 'padding', '20px'],
159             ['d', 'border-radius', '8px'],
160             ['d', 'box-shadow', '0 2px 4px rgba(0, 0, 0, 0.1)'],
161             ['d', 'font-family', 'Arial, Helvetica, sans-serif'],
162             ['e'],
163              
164             ['s', '.'.$self->{'css_class'}.' .version'],
165             ['d', 'border-bottom', '2px solid #eee'],
166             ['d', 'padding-bottom', '20px'],
167             ['d', 'margin-bottom', '20px'],
168             ['e'],
169              
170             ['s', '.'.$self->{'css_class'}.' .version:last-child'],
171             ['d', 'border-bottom', 'none'],
172             ['e'],
173              
174             ['s', '.'.$self->{'css_class'}.' .version h2'],
175             ['s', '.'.$self->{'css_class'}.' .version h3'],
176             ['d', 'color', '#007BFF'],
177             ['d', 'margin-top', 0],
178             ['e'],
179              
180             ['s', '.'.$self->{'css_class'}.' .version-changes'],
181             ['d', 'list-style-type', 'none'],
182             ['d', 'padding-left', 0],
183             ['e'],
184              
185 2         107 ['s', '.'.$self->{'css_class'}.' .version-change'],
186             ['d', 'background-color', '#f8f9fa'],
187             ['d', 'margin', '10px 0'],
188             ['d', 'padding', '10px'],
189             ['d', 'border-left', '4px solid #007BFF'],
190             ['d', 'border-radius', '4px'],
191             ['e'],
192             );
193              
194 2         2188 return;
195             }
196              
197             1;
198              
199             __END__