line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Formatter::HTML::Preformatted; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
34349
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
90
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
109
|
|
5
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
88
|
|
6
|
2
|
|
|
2
|
|
2029
|
use URI::Find::Simple qw( list_uris change_uris ); |
|
2
|
|
|
|
|
62766
|
|
|
2
|
|
|
|
|
931
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.95'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Formatter::HTML::Preformatted - Absolute minimal HTML formatting of pure text |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Formatter::HTML::Preformatted; |
18
|
|
|
|
|
|
|
my $formatter = Formatter::HTML::Preformatted->format($data); |
19
|
|
|
|
|
|
|
print $formatter->fragment; |
20
|
|
|
|
|
|
|
my @links = $text->links; |
21
|
|
|
|
|
|
|
print ${$links}[0]->{url}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This module will simply take any text-string and put it in a HTML |
26
|
|
|
|
|
|
|
C element. It will escape tags and entities. It will also look |
27
|
|
|
|
|
|
|
through it to see if there are any URIs, and they will be turned into |
28
|
|
|
|
|
|
|
hyperlinks. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 METHODS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This module conforms with the L API specification, version 0.95: |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item C |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The format function that you call to initialise the formatter. It |
39
|
|
|
|
|
|
|
takes the plain text as a string argument and returns an object of |
40
|
|
|
|
|
|
|
this class. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub format { |
45
|
1
|
|
|
1
|
1
|
805
|
my $that = shift; |
46
|
1
|
|
33
|
|
|
10
|
my $class = ref($that) || $that; |
47
|
1
|
|
|
|
|
3
|
my $self = { |
48
|
|
|
|
|
|
|
_text => shift, |
49
|
|
|
|
|
|
|
}; |
50
|
1
|
|
|
|
|
3
|
bless($self, $class); |
51
|
1
|
|
|
|
|
3
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item C |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
To get only the text enclosed in the minimal C element, you will |
57
|
|
|
|
|
|
|
call this method. It returns a string with the HTML fragment. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub fragment { |
62
|
2
|
|
|
2
|
1
|
543
|
my $self = shift; |
63
|
2
|
|
|
|
|
11
|
my $raw = $self->{_text}; |
64
|
|
|
|
|
|
|
# Escaping the stuff that needs escaping. |
65
|
2
|
|
|
|
|
6
|
$raw =~ s/&/&/g; |
66
|
2
|
|
|
|
|
5
|
$raw =~ s/\>/>/g; |
67
|
2
|
|
|
|
|
6
|
$raw =~ s/\</g; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
4
|
|
14
|
return "\n" . change_uris($raw, sub { "$_[0]" }) . "\n \n"; |
|
4
|
|
|
|
|
38632
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item C |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Will add a document type declaration and some minimal markup, to |
75
|
|
|
|
|
|
|
return a full, valid, HTML document. You may specify an optional |
76
|
|
|
|
|
|
|
C<$charset> parameter. This will include a HTML C element with |
77
|
|
|
|
|
|
|
the chosen character set. It will still be your responsibility to |
78
|
|
|
|
|
|
|
ensure that the document served is encoded with this character set. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub document { |
83
|
1
|
|
|
1
|
1
|
817
|
my $self = shift; |
84
|
1
|
|
|
|
|
3
|
my $result = '' . "\n\n"; |
85
|
1
|
|
|
|
|
3
|
my $charset = shift; |
86
|
1
|
50
|
|
|
|
7
|
if ($charset) { |
87
|
1
|
|
|
|
|
6
|
$result .= "\n" . '' . "\n\n"; |
88
|
|
|
|
|
|
|
} |
89
|
1
|
|
|
|
|
4
|
$result .= "\n" . $self->fragment . "\n\n\n"; |
90
|
1
|
|
|
|
|
96
|
return $result; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item C |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Will return all links found the input plain text string. They will be |
97
|
|
|
|
|
|
|
found in an arrayref where each element has a key C. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub links { |
102
|
1
|
|
|
1
|
1
|
1089
|
my $self = shift; |
103
|
1
|
|
|
|
|
4
|
my @arr; |
104
|
1
|
|
|
|
|
8
|
foreach (list_uris($self->{_text})) { |
105
|
2
|
|
|
|
|
711
|
push(@arr, {url => $_, title => ''}); |
106
|
|
|
|
|
|
|
} |
107
|
1
|
|
|
|
|
8
|
return \@arr; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item C |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Since this formatter has no way of finding the title of the document |
113
|
|
|
|
|
|
|
this method will always return C. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub title { |
119
|
0
|
|
|
0
|
1
|
|
return undef; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
__END__ |