| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Pod::Simple::Role::XHTML::WithErrata; | 
| 2 | 1 |  |  | 1 |  | 83366 | use Moo::Role; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | our $VERSION = '0.003002'; | 
| 5 |  |  |  |  |  |  | $VERSION =~ tr/_//d; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 298 | use HTML::Entities qw(encode_entities); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 59 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 381 | use namespace::clean; | 
|  | 1 |  |  |  |  | 9222 |  | 
|  | 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 |  | 2 | my $self = shift; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | my $tag = sub { | 
| 27 | 8 |  |  | 8 |  | 11 | my $name       = shift; | 
| 28 | 8 |  |  |  |  | 9 | my $attributes = ''; | 
| 29 | 8 | 100 |  |  |  | 15 | if ( ref( $_[0] ) ) { | 
| 30 | 2 |  |  |  |  | 9 | my $attr = shift; | 
| 31 | 2 |  |  |  |  | 13 | while ( my ( $k, $v ) = each %$attr ) { | 
| 32 | 2 |  |  |  |  | 5 | $attributes .= qq{ $k="} . encode_entities($v) . '"'; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  | } | 
| 35 | 8 | 100 |  |  |  | 36 | my @body = map { /^ ? $_ : encode_entities($_) } @_; | 
|  | 11 |  |  |  |  | 32 |  | 
| 36 | 8 |  |  |  |  | 88 | return join( '', "<$name$attributes>", @body, "$name>" ); | 
| 37 | 1 |  |  |  |  | 5 | }; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | my @errors = map { | 
| 40 | 1 |  |  |  |  | 2 | my $line  = $_; | 
| 41 | 1 |  |  |  |  | 2 | my $error = $self->{'errata'}->{$line}; | 
| 42 |  |  |  |  |  |  | ( | 
| 43 |  |  |  |  |  |  | $tag->( 'dt', "Around line $line:" ), | 
| 44 | 1 |  |  |  |  | 5 | $tag->( 'dd', map { $tag->( 'p', $_ ) } @$error ), | 
|  | 1 |  |  |  |  | 3 |  | 
| 45 |  |  |  |  |  |  | ); | 
| 46 | 1 |  |  |  |  | 2 | } sort { $a <=> $b } keys %{ $self->{'errata'} }; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 1 |  |  |  |  | 3 |  | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 1 |  |  |  |  | 2 | my $error_count = keys %{ $self->{'errata'} }; | 
|  | 1 |  |  |  |  | 3 |  | 
| 49 | 1 | 50 |  |  |  | 2 | 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 |  |  |  |  | 4 | $self->emit; | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | 1; | 
| 69 |  |  |  |  |  |  | __END__ |