line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Markup; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
154683
|
use 5.8.1; |
|
2
|
|
|
|
|
15
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
5
|
2
|
|
|
2
|
|
22
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
60
|
|
6
|
2
|
|
|
2
|
|
829
|
use Text::Markup::None; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
75
|
|
7
|
2
|
|
|
2
|
|
16
|
use Carp; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
1671
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %_PARSER_FOR; |
12
|
|
|
|
|
|
|
my %REGEX_FOR = ( |
13
|
|
|
|
|
|
|
html => qr{x?html?}, |
14
|
|
|
|
|
|
|
markdown => qr{m(?:d(?:own)?|kdn?|arkdown)}, |
15
|
|
|
|
|
|
|
multimarkdown => qr{mm(?:d(?:own)?|kdn?|arkdown)}, |
16
|
|
|
|
|
|
|
pod => qr{p(?:od|m|l)}, |
17
|
|
|
|
|
|
|
textile => qr{textile}, |
18
|
|
|
|
|
|
|
trac => qr{tra?c}, |
19
|
|
|
|
|
|
|
mediawiki => qr{(?:m(?:edia)?)?wiki}, |
20
|
|
|
|
|
|
|
rest => qr{re?st}, |
21
|
|
|
|
|
|
|
asciidoc => qr{a(?:sc(?:iidoc)?|doc)?}, |
22
|
|
|
|
|
|
|
bbcode => qr{bb(?:code)?}, |
23
|
|
|
|
|
|
|
creole => qr{creole}, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub register { |
27
|
2
|
|
|
2
|
1
|
3794
|
my ($class, $name, $regex) = @_; |
28
|
2
|
|
|
|
|
6
|
my $pkg = caller; |
29
|
2
|
|
|
|
|
7
|
$REGEX_FOR{$name} = $regex; |
30
|
2
|
50
|
|
|
|
46
|
$_PARSER_FOR{$name} = $pkg->can('parser') |
31
|
|
|
|
|
|
|
or croak "No parser() function defind in $pkg"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _parser_for { |
35
|
28
|
|
|
28
|
|
88
|
my ($self, $format) = @_; |
36
|
28
|
100
|
|
|
|
93
|
return Text::Markup::None->can('parser') unless $format; |
37
|
26
|
100
|
|
|
|
115
|
return $_PARSER_FOR{$format} if $_PARSER_FOR{$format}; |
38
|
10
|
100
|
|
|
|
82
|
my $pkg = __PACKAGE__ . '::' . ($format eq 'html' ? 'HTML' : ucfirst $format); |
39
|
10
|
50
|
|
|
|
662
|
eval "require $pkg; 1" or die $@; |
40
|
10
|
|
33
|
|
|
162
|
return $_PARSER_FOR{$format} = $pkg->can('parser') |
41
|
|
|
|
|
|
|
|| croak "No parser() function defind in $pkg"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub formats { |
45
|
13
|
|
|
13
|
1
|
5867
|
sort keys %REGEX_FOR; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
1
|
14
|
sub format_matchers { %REGEX_FOR } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
11
|
|
|
11
|
1
|
577
|
my $class = shift; |
52
|
11
|
|
|
|
|
71
|
bless { default_encoding => 'UTF-8', @_ } => $class; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub parse { |
56
|
24
|
|
|
24
|
1
|
14960
|
my $self = shift; |
57
|
24
|
|
|
|
|
116
|
my %p = @_; |
58
|
24
|
50
|
|
|
|
92
|
my $file = $p{file} or croak "No file parameter passed to parse()"; |
59
|
24
|
50
|
33
|
|
|
577
|
croak "$file does not exist" unless -e $file && !-d _; |
60
|
|
|
|
|
|
|
|
61
|
24
|
|
|
|
|
124
|
my $parser = $self->_get_parser(\%p); |
62
|
|
|
|
|
|
|
return $parser->( |
63
|
|
|
|
|
|
|
$file, |
64
|
|
|
|
|
|
|
$p{encoding} || $self->default_encoding, |
65
|
|
|
|
|
|
|
$p{options} |
66
|
24
|
|
33
|
|
|
114
|
); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub default_format { |
70
|
8
|
|
|
8
|
1
|
1493
|
my $self = shift; |
71
|
8
|
100
|
|
|
|
42
|
return $self->{default_format} unless @_; |
72
|
3
|
|
|
|
|
10
|
$self->{default_format} = shift; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub default_encoding { |
76
|
24
|
|
|
24
|
1
|
48
|
my $self = shift; |
77
|
24
|
50
|
|
|
|
192
|
return $self->{default_encoding} unless @_; |
78
|
0
|
|
|
|
|
0
|
$self->{default_encoding} = shift; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _get_parser { |
82
|
28
|
|
|
28
|
|
71
|
my ($self, $p) = @_; |
83
|
|
|
|
|
|
|
my $format = $p->{format} |
84
|
|
|
|
|
|
|
|| $self->guess_format($p->{file}) |
85
|
28
|
|
100
|
|
|
117
|
|| $self->default_format; |
86
|
|
|
|
|
|
|
|
87
|
28
|
|
|
|
|
88
|
return $self->_parser_for($format); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub guess_format { |
91
|
36
|
|
|
36
|
1
|
15035
|
my ($self, $file) = @_; |
92
|
36
|
|
|
|
|
183
|
for my $format (keys %REGEX_FOR) { |
93
|
217
|
100
|
|
|
|
5230
|
return $format if $file =~ qr{[.]$REGEX_FOR{$format}$}; |
94
|
|
|
|
|
|
|
} |
95
|
5
|
|
|
|
|
75
|
return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
__END__ |