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
|
|
215129
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
91
|
|
28
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
78
|
|
29
|
2
|
|
|
2
|
|
27
|
use base 'Template::Plugin'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3612
|
|
30
|
2
|
|
|
2
|
|
5018
|
use Text::Autoformat; |
|
2
|
|
|
|
|
207605
|
|
|
2
|
|
|
|
|
1554
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '2.75'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
22
|
|
|
22
|
1
|
138171
|
my ( $class, $context, $options ) = @_; |
36
|
22
|
|
|
|
|
53
|
my $filter_factory; |
37
|
|
|
|
|
|
|
my $plugin; |
38
|
|
|
|
|
|
|
|
39
|
22
|
100
|
|
|
|
91
|
if ($options) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# create a closure to generate filters with additional options |
42
|
|
|
|
|
|
|
$filter_factory = sub { |
43
|
4
|
|
|
4
|
|
220
|
my $context = shift; |
44
|
4
|
100
|
|
|
|
23
|
my $filtopt = ref $_[-1] eq 'HASH' ? pop : {}; |
45
|
4
|
|
|
|
|
26
|
@$filtopt{ keys %$options } = values %$options; |
46
|
|
|
|
|
|
|
return sub { |
47
|
4
|
|
|
|
|
176
|
tt_autoformat( @_, $filtopt ); |
48
|
4
|
|
|
|
|
32
|
}; |
49
|
12
|
|
|
|
|
99
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# and a closure to represent the plugin |
52
|
|
|
|
|
|
|
$plugin = sub { |
53
|
16
|
100
|
|
16
|
|
5788
|
my $plugopt = ref $_[-1] eq 'HASH' ? pop : {}; |
54
|
16
|
|
|
|
|
87
|
@$plugopt{ keys %$options } = values %$options; |
55
|
16
|
|
|
|
|
50
|
tt_autoformat( @_, $plugopt ); |
56
|
12
|
|
|
|
|
69
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
|
|
|
|
|
|
# simple filter factory closure (no legacy options from constructor) |
60
|
|
|
|
|
|
|
$filter_factory = sub { |
61
|
4
|
|
|
4
|
|
194
|
my $context = shift; |
62
|
4
|
50
|
|
|
|
17
|
my $filtopt = ref $_[-1] eq 'HASH' ? pop : {}; |
63
|
|
|
|
|
|
|
return sub { |
64
|
6
|
|
|
|
|
124
|
tt_autoformat( @_, $filtopt ); |
65
|
4
|
|
|
|
|
26
|
}; |
66
|
10
|
|
|
|
|
72
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# plugin without options can be static |
69
|
10
|
|
|
|
|
32
|
$plugin = \&tt_autoformat; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# now define the filter and return the plugin |
73
|
22
|
|
|
|
|
148
|
$context->define_filter( 'Autoformat', [ $filter_factory => 1 ] ); |
74
|
22
|
|
|
|
|
1184
|
return $plugin; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub tt_autoformat { |
78
|
32
|
100
|
|
32
|
0
|
525
|
my $options = ref $_[-1] eq 'HASH' ? pop : {}; |
79
|
32
|
|
|
|
|
74
|
my $form = $options->{form}; |
80
|
32
|
100
|
|
|
|
219
|
my $out |
81
|
|
|
|
|
|
|
= $form |
82
|
|
|
|
|
|
|
? Text::Autoformat::form( $options, $form, @_ ) |
83
|
|
|
|
|
|
|
: Text::Autoformat::autoformat( join( '', @_ ), $options ); |
84
|
32
|
|
|
|
|
68770
|
return $out; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |