| blib/lib/Template/Plugin/PwithBR.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 22 | 22 | 100.0 |
| branch | n/a | ||
| condition | 1 | 3 | 33.3 |
| subroutine | 6 | 6 | 100.0 |
| pod | 1 | 2 | 50.0 |
| total | 30 | 33 | 90.9 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Template::Plugin::PwithBR; | ||||||
| 2 | |||||||
| 3 | 2 | 2 | 191544 | use strict; | |||
| 2 | 6 | ||||||
| 2 | 96 | ||||||
| 4 | 2 | 2 | 13 | use warnings; | |||
| 2 | 4 | ||||||
| 2 | 71 | ||||||
| 5 | |||||||
| 6 | 2 | 2 | 11 | use base qw( Template::Plugin ); | |||
| 2 | 8 | ||||||
| 2 | 2137 | ||||||
| 7 | 2 | 2 | 9737 | use Template::Plugin; | |||
| 2 | 8 | ||||||
| 2 | 554 | ||||||
| 8 | |||||||
| 9 | our $FILTER_NAME = 'p_with_br'; | ||||||
| 10 | |||||||
| 11 | our $VERSION = '0.04'; | ||||||
| 12 | |||||||
| 13 | sub new { | ||||||
| 14 | 4 | 4 | 1 | 11901 | my($class, $context, @args) = @_; | ||
| 15 | 4 | 33 | 20 | my $name = $args[0] || $FILTER_NAME; | |||
| 16 | 4 | 20 | $context->define_filter($name, \&p_with_br, 0); | ||||
| 17 | 4 | 86 | return $class; | ||||
| 18 | } | ||||||
| 19 | |||||||
| 20 | sub p_with_br { | ||||||
| 21 | 4 | 4 | 0 | 378 | my $text = shift; | ||
| 22 | 4 | 9 | $text =~ s/\x0D\x0A/\n/g; | ||||
| 23 | 4 | 8 | $text =~ tr/\x0D\x0A/\n\n/; | ||||
| 24 | |||||||
| 25 | 4 | 27 | $text =~ s{(?\n}g; | ||||
| 26 | 4 | 34 | $text = " \n" |
||||
| 27 | . join("\n\n\n \n", split(/(?:\r?\n){2,}/, $text)) |
||||||
| 28 | . "\n"; | ||||||
| 29 | 4 | 13 | $text; | ||||
| 30 | } | ||||||
| 31 | |||||||
| 32 | 1; | ||||||
| 33 | __END__ |