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
|
|
93488
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
78
|
|
28
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
72
|
|
29
|
2
|
|
|
2
|
|
21
|
use base 'Template::Plugin'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1609
|
|
30
|
2
|
|
|
2
|
|
2160
|
use Text::Autoformat; |
|
2
|
|
|
|
|
78357
|
|
|
2
|
|
|
|
|
751
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '2.77'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
23
|
|
|
23
|
1
|
56369
|
my ( $class, $context, $options ) = @_; |
36
|
23
|
|
|
|
|
25
|
my $filter_factory; |
37
|
|
|
|
|
|
|
my $plugin; |
38
|
|
|
|
|
|
|
|
39
|
23
|
100
|
|
|
|
36
|
if ($options) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# create a closure to generate filters with additional options |
42
|
|
|
|
|
|
|
$filter_factory = sub { |
43
|
4
|
|
|
4
|
|
134
|
my $context = shift; |
44
|
4
|
100
|
|
|
|
10
|
my $filtopt = ref $_[-1] eq 'HASH' ? pop : {}; |
45
|
4
|
|
|
|
|
11
|
@$filtopt{ keys %$options } = values %$options; |
46
|
|
|
|
|
|
|
return sub { |
47
|
4
|
|
|
|
|
89
|
_tt_autoformat( @_, $filtopt ); |
48
|
4
|
|
|
|
|
16
|
}; |
49
|
12
|
|
|
|
|
53
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# and a closure to represent the plugin |
52
|
|
|
|
|
|
|
$plugin = sub { |
53
|
16
|
100
|
|
16
|
|
4658
|
my $plugopt = ref $_[-1] eq 'HASH' ? pop : {}; |
54
|
16
|
|
|
|
|
57
|
@$plugopt{ keys %$options } = values %$options; |
55
|
16
|
|
|
|
|
35
|
_tt_autoformat( @_, $plugopt ); |
56
|
12
|
|
|
|
|
34
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
|
|
|
|
|
|
# simple filter factory closure (no legacy options from constructor) |
60
|
|
|
|
|
|
|
$filter_factory = sub { |
61
|
5
|
|
|
5
|
|
219
|
my $context = shift; |
62
|
5
|
100
|
|
|
|
15
|
my $filtopt = ref $_[-1] eq 'HASH' ? pop : {}; |
63
|
|
|
|
|
|
|
return sub { |
64
|
7
|
|
|
|
|
104
|
_tt_autoformat( @_, $filtopt ); |
65
|
5
|
|
|
|
|
18
|
}; |
66
|
11
|
|
|
|
|
42
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# plugin without options can be static |
69
|
11
|
|
|
|
|
15
|
$plugin = \&_tt_autoformat; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# now define the filter and return the plugin |
73
|
23
|
|
|
|
|
70
|
$context->define_filter( 'Autoformat', [ $filter_factory => 1 ] ); |
74
|
23
|
|
|
|
|
356
|
return $plugin; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _tt_autoformat { |
78
|
33
|
100
|
|
33
|
|
185
|
my $options = ref $_[-1] eq 'HASH' ? pop : {}; |
79
|
33
|
|
|
|
|
34
|
my $form = $options->{form}; |
80
|
33
|
100
|
|
|
|
113
|
my $out |
81
|
|
|
|
|
|
|
= $form |
82
|
|
|
|
|
|
|
? Text::Autoformat::form( $options, $form, @_ ) |
83
|
|
|
|
|
|
|
: Text::Autoformat::autoformat( join( '', @_ ), $options ); |
84
|
33
|
|
|
|
|
37061
|
return $out; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |