line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#============================================================= -*-Perl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Template::Plugin::Autoformat |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# Plugin interface to Damian Conway's Text::Autoformat module. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# AUTHORS |
9
|
|
|
|
|
|
|
# Robert McArthur |
10
|
|
|
|
|
|
|
# - original plugin code |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Andy Wardley |
13
|
|
|
|
|
|
|
# - added FILTER registration, support for forms and some additional |
14
|
|
|
|
|
|
|
# documentation |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# COPYRIGHT |
17
|
|
|
|
|
|
|
# Copyright (C) 2000-2008 Robert McArthur, Andy Wardley. |
18
|
|
|
|
|
|
|
# All Rights Reserved. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
21
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
#============================================================================ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package Template::Plugin::Autoformat; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
119612
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
94
|
|
28
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
75
|
|
29
|
2
|
|
|
2
|
|
26
|
use base 'Template::Plugin'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1165
|
|
30
|
2
|
|
|
2
|
|
2498
|
use Text::Autoformat; |
|
2
|
|
|
|
|
98496
|
|
|
2
|
|
|
|
|
940
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '2.76'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
22
|
|
|
22
|
1
|
102123
|
my ( $class, $context, $options ) = @_; |
36
|
22
|
|
|
|
|
52
|
my $filter_factory; |
37
|
|
|
|
|
|
|
my $plugin; |
38
|
|
|
|
|
|
|
|
39
|
22
|
100
|
|
|
|
83
|
if ($options) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# create a closure to generate filters with additional options |
42
|
|
|
|
|
|
|
$filter_factory = sub { |
43
|
4
|
|
|
4
|
|
241
|
my $context = shift; |
44
|
4
|
100
|
|
|
|
22
|
my $filtopt = ref $_[-1] eq 'HASH' ? pop : {}; |
45
|
4
|
|
|
|
|
21
|
@$filtopt{ keys %$options } = values %$options; |
46
|
|
|
|
|
|
|
return sub { |
47
|
4
|
|
|
|
|
149
|
tt_autoformat( @_, $filtopt ); |
48
|
4
|
|
|
|
|
33
|
}; |
49
|
12
|
|
|
|
|
99
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# and a closure to represent the plugin |
52
|
|
|
|
|
|
|
$plugin = sub { |
53
|
16
|
100
|
|
16
|
|
4846
|
my $plugopt = ref $_[-1] eq 'HASH' ? pop : {}; |
54
|
16
|
|
|
|
|
88
|
@$plugopt{ keys %$options } = values %$options; |
55
|
16
|
|
|
|
|
50
|
tt_autoformat( @_, $plugopt ); |
56
|
12
|
|
|
|
|
71
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
|
|
|
|
|
|
# simple filter factory closure (no legacy options from constructor) |
60
|
|
|
|
|
|
|
$filter_factory = sub { |
61
|
4
|
|
|
4
|
|
252
|
my $context = shift; |
62
|
4
|
50
|
|
|
|
21
|
my $filtopt = ref $_[-1] eq 'HASH' ? pop : {}; |
63
|
|
|
|
|
|
|
return sub { |
64
|
6
|
|
|
|
|
173
|
tt_autoformat( @_, $filtopt ); |
65
|
4
|
|
|
|
|
32
|
}; |
66
|
10
|
|
|
|
|
91
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# plugin without options can be static |
69
|
10
|
|
|
|
|
38
|
$plugin = \&tt_autoformat; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# now define the filter and return the plugin |
73
|
22
|
|
|
|
|
147
|
$context->define_filter( 'Autoformat', [ $filter_factory => 1 ] ); |
74
|
22
|
|
|
|
|
732
|
return $plugin; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub tt_autoformat { |
78
|
32
|
100
|
|
32
|
0
|
365
|
my $options = ref $_[-1] eq 'HASH' ? pop : {}; |
79
|
32
|
|
|
|
|
65
|
my $form = $options->{form}; |
80
|
32
|
100
|
|
|
|
214
|
my $out |
81
|
|
|
|
|
|
|
= $form |
82
|
|
|
|
|
|
|
? Text::Autoformat::form( $options, $form, @_ ) |
83
|
|
|
|
|
|
|
: Text::Autoformat::autoformat( join( '', @_ ), $options ); |
84
|
32
|
|
|
|
|
58603
|
return $out; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |