line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Markup::Any; |
2
|
3
|
|
|
3
|
|
116216
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
108
|
|
3
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
75
|
|
4
|
3
|
|
|
3
|
|
899
|
use utf8; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
18
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
2386
|
use parent 'Exporter'; |
|
3
|
|
|
|
|
883
|
|
|
3
|
|
|
|
|
15
|
|
8
|
3
|
|
|
3
|
|
1707
|
use Class::Load qw/load_class/; |
|
3
|
|
|
|
|
73524
|
|
|
3
|
|
|
|
|
2143
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw/markupper/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $markdown = {markup_method => 'markdown'}; |
13
|
|
|
|
|
|
|
our %MODULES = ( |
14
|
|
|
|
|
|
|
'Text::Markdown' => $markdown, |
15
|
|
|
|
|
|
|
'Text::MultiMarkdown' => $markdown, |
16
|
|
|
|
|
|
|
'Text::Markdown::Discount' => $markdown, |
17
|
|
|
|
|
|
|
'Text::Markdown::GitHubAPI' => $markdown, |
18
|
|
|
|
|
|
|
'Text::Markdown::Hoedown' => { |
19
|
|
|
|
|
|
|
class => 'Text::Markdown::Hoedown::Markdown', |
20
|
|
|
|
|
|
|
markup_method => 'render', |
21
|
|
|
|
|
|
|
args => sub { [0, 16, Text::Markdown::Hoedown::Renderer::HTML->new(0, 99)] }, |
22
|
|
|
|
|
|
|
deref => 1, |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
'Text::Xatena' => {markup_method => 'format'}, |
25
|
|
|
|
|
|
|
'Text::Textile' => {markup_method => 'process'}, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
4
|
|
|
4
|
0
|
56153
|
my ($pkg, $class, @args) = @_; |
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
|
|
9
|
my $args; |
32
|
4
|
50
|
|
|
|
21
|
if (@args) { |
33
|
0
|
0
|
|
|
|
0
|
$args = ref $args[0] ? $args[0] : {@args}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
4
|
50
|
|
|
|
22
|
my $info = $MODULES{$class} |
37
|
|
|
|
|
|
|
or die "no configuration found: $class. You want to use $class, directory call $pkg->adaptor constractor."; |
38
|
|
|
|
|
|
|
|
39
|
4
|
50
|
|
|
|
19
|
if ($args) { |
40
|
0
|
0
|
0
|
|
|
0
|
if ($info->{args} && ref($info->{args}) eq 'HASH') { |
41
|
0
|
|
|
|
|
0
|
$info->{args} = { |
42
|
0
|
|
|
|
|
0
|
%{ $info->{args} }, |
43
|
|
|
|
|
|
|
%$args, |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
0
|
|
|
|
|
0
|
$info->{args} = $args; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
4
|
100
|
|
|
|
20
|
load_class($class) if $info->{class}; |
52
|
4
|
|
|
|
|
98
|
$pkg->adaptor( |
53
|
|
|
|
|
|
|
class => $class, |
54
|
|
|
|
|
|
|
%$info, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# taken from Ark::Models |
59
|
|
|
|
|
|
|
sub adaptor { |
60
|
4
|
|
|
4
|
0
|
19
|
my ($pkg, %info) = @_; |
61
|
|
|
|
|
|
|
|
62
|
4
|
50
|
|
|
|
16
|
my $class = $info{class} or die q{Required class parameter}; |
63
|
4
|
50
|
|
|
|
15
|
my $markup_method = $info{markup_method} or die q{Required markup_method parameter}; |
64
|
4
|
|
50
|
|
|
23
|
my $constructor = $info{constructor} || 'new'; |
65
|
|
|
|
|
|
|
|
66
|
4
|
|
|
|
|
18
|
load_class($class); |
67
|
4
|
100
|
|
|
|
51232
|
$info{args} = $info{args}->() if ref $info{args} eq 'CODE'; |
68
|
|
|
|
|
|
|
|
69
|
4
|
|
|
|
|
8
|
my $instance; |
70
|
4
|
100
|
66
|
|
|
28
|
if ($info{deref} and my $args = $info{args}) { |
|
|
50
|
|
|
|
|
|
71
|
1
|
50
|
|
|
|
6
|
if (ref($args) eq 'HASH') { |
|
|
50
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
$instance = $class->$constructor(%$args); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif (ref($args) eq 'ARRAY') { |
75
|
1
|
|
|
|
|
20
|
$instance = $class->$constructor(@$args); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
|
|
|
|
0
|
die qq{Couldn't dereference: $args}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
elsif ($info{args}) { |
82
|
0
|
|
|
|
|
0
|
$instance = $class->$constructor($info{args}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
3
|
|
|
|
|
19
|
$instance = $class->$constructor; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
89
|
bless { |
89
|
|
|
|
|
|
|
_instance => $instance, |
90
|
|
|
|
|
|
|
_markup_method => $markup_method, |
91
|
|
|
|
|
|
|
}, $pkg; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub markup { |
95
|
4
|
|
|
4
|
0
|
28
|
my ($self, @text) = @_; |
96
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
21
|
my $meth = $self->{_markup_method}; |
98
|
4
|
|
|
|
|
54
|
$self->{_instance}->$meth(@text); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub markupper { |
102
|
1
|
|
|
1
|
0
|
33890
|
my $class = shift; |
103
|
1
|
50
|
|
|
|
8
|
$class = "Text::$class" unless $class =~ /^\+/; |
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
9
|
__PACKAGE__->new($class, @_); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |