File Coverage

blib/lib/Text/Translate/Format/Pod.pm
Criterion Covered Total %
statement 34 34 100.0
branch 5 6 83.3
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 49 50 98.0


line stmt bran cond sub pod time code
1             package Text::Translate::Format::Pod;
2             BEGIN {
3 1     1   21 $Text::Translate::Format::Pod::VERSION = '0.1.0_01';
4             }
5             # ABSTRACT: POD handler for Text::Translate::Format
6              
7 1     1   6 use strict;
  1         2  
  1         31  
8 1     1   5 use warnings;
  1         1  
  1         31  
9 1     1   5 use Carp;
  1         1  
  1         70  
10 1     1   5 use English qw( -no_match_vars );
  1         3  
  1         8  
11              
12 1     1   540 use base 'Text::Translate::Format';
  1         2  
  1         959  
13              
14             # Module implementation here
15             sub text_to_paragraphs {
16 1     1 1 2 my ($self) = @_;
17 1         3 (my $text = $self->text()) =~ s/\A\n+|\n+\z//mxs;
18              
19 1         2 my (@buffer, @paragraphs);
20 1         10 my @candidates = split /\n\s*\n/, $text;
21 1         2 for my $candidate (@candidates) {
22 5 100       11 if ($candidate =~ /\A\s/mxs) {
23 2         3 push @buffer, $candidate;
24 2         3 next;
25             }
26 3 100       7 if (@buffer) {
27 1         3 push @paragraphs, join "\n\n", @buffer;
28 1         2 @buffer = ();
29             }
30 3         7 push @paragraphs, $candidate;
31             }
32 1 50       5 push @paragraphs, join "\n\n", @buffer if @buffer;
33              
34 1         6 $self->paragraphs(\@paragraphs);
35 1         5 return $self;
36             }
37              
38             sub paragraphs_to_text {
39 1     1 1 753 my ($self) = @_;
40 1         5 $self->text(join("\n\n", $self->paragraphs()) . "\n");
41 1         3 return $self;
42             }
43              
44             1;
45              
46              
47             =pod
48              
49             =head1 NAME
50              
51             Text::Translate::Format::Pod - POD handler for Text::Translate::Format
52              
53             =head1 VERSION
54              
55             version 0.1.0_01
56              
57             =head1 DESCRIPTION
58              
59             This module fits into the L system for handling
60             conversion between POD documents and paragraphs (suitable for translating
61             via L) and vice-versa.
62              
63             =head1 METHODS
64              
65             =head2 text_to_paragraphs
66              
67             Overridden method from L.
68              
69             =head2 paragraphs_to_text
70              
71             Overridden method from L.
72              
73             =head1 AUTHOR
74              
75             Flavio Poletti
76              
77             =head1 COPYRIGHT AND LICENSE
78              
79             Copyright (C) 2010 by Flavio Poletti.
80              
81             This module is free software. You can redistribute it and/or
82             modify it under the terms of the Artistic License 2.0.
83              
84             This program is distributed in the hope that it will be useful,
85             but without any warranty; without even the implied warranty of
86             merchantability or fitness for a particular purpose.
87              
88             =cut
89              
90              
91             __END__