File Coverage

blib/lib/Pod/Simple/Role/XHTML/WithErrata.pm
Criterion Covered Total %
statement 31 32 96.8
branch 5 6 83.3
condition n/a
subroutine 5 5 100.0
pod n/a
total 41 43 95.3


line stmt bran cond sub pod time code
1             package Pod::Simple::Role::XHTML::WithErrata;
2 1     1   82689 use Moo::Role;
  1         2  
  1         5  
3              
4             our $VERSION = '0.003000';
5             $VERSION =~ tr/_//d;
6              
7 1     1   297 use HTML::Entities qw(encode_entities);
  1         1  
  1         58  
8              
9 1     1   377 use namespace::clean;
  1         9046  
  1         5  
10              
11             around _gen_errata => sub {
12             return; # override the default errata formatting
13             };
14              
15             around end_Document => sub {
16             my $orig = shift;
17             my $self = shift;
18             $self->_emit_custom_errata
19             if $self->{errata};
20             $self->$orig(@_);
21             };
22              
23             sub _emit_custom_errata {
24 1     1   1 my $self = shift;
25              
26             my $tag = sub {
27 8     8   12 my $name = shift;
28 8         9 my $attributes = '';
29 8 100       16 if ( ref( $_[0] ) ) {
30 2         11 my $attr = shift;
31 2         11 while ( my ( $k, $v ) = each %$attr ) {
32 2         6 $attributes .= qq{ $k="} . encode_entities($v) . '"';
33             }
34             }
35 8 100       34 my @body = map { /^
  11         44  
36 8         93 return join( '', "<$name$attributes>", @body, "" );
37 1         6 };
38              
39             my @errors = map {
40 1         3 my $line = $_;
41 1         1 my $error = $self->{'errata'}->{$line};
42             (
43             $tag->( 'dt', "Around line $line:" ),
44 1         4 $tag->( 'dd', map { $tag->( 'p', $_ ) } @$error ),
  1         2  
45             );
46 1         2 } sort { $a <=> $b } keys %{ $self->{'errata'} };
  0         0  
  1         4  
47              
48 1         2 my $error_count = keys %{ $self->{'errata'} };
  1         3  
49 1 50       4 my $s = $error_count == 1 ? '' : 's';
50              
51 1         4 $self->{'scratch'} = $tag->(
52             'div',
53             { class => "pod-errors" },
54             $tag->( 'p', "$error_count POD Error$s" ),
55             $tag->(
56             'div',
57             { class => "pod-errors-detail" },
58             $tag->(
59             'p',
60             'The following errors were encountered while parsing the POD:'
61             ),
62             $tag->( 'dl', @errors ),
63             ),
64             );
65 1         5 $self->emit;
66             }
67              
68             1;
69             __END__