Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / i486-linux-gnu-thread-multi / Template / Plugin / Wrap.pm
1 #============================================================= -*-Perl-*-
2 #
3 # Template::Plugin::Wrap
4 #
5 # DESCRIPTION
6 #   Plugin for wrapping text via the Text::Wrap module.
7 #
8 # AUTHOR
9 #   Andy Wardley   <abw@wardley.org>
10 #
11 # COPYRIGHT
12 #   Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
13 #
14 #   This module is free software; you can redistribute it and/or
15 #   modify it under the same terms as Perl itself.
16 #
17 #============================================================================
18
19 package Template::Plugin::Wrap;
20
21 use strict;
22 use warnings;
23 use base 'Template::Plugin';
24 use Text::Wrap;
25
26 our $VERSION = 2.68;
27
28 sub new {
29     my ($class, $context, $format) = @_;;
30     $context->define_filter('wrap', [ \&wrap_filter_factory => 1 ]);
31     return \&tt_wrap;
32 }
33
34 sub tt_wrap {
35     my $text  = shift;
36     my $width = shift || 72;
37     my $itab  = shift;
38     my $ntab  = shift;
39     $itab = '' unless defined $itab;
40     $ntab = '' unless defined $ntab;
41     $Text::Wrap::columns = $width;
42     Text::Wrap::wrap($itab, $ntab, $text);
43 }
44
45 sub wrap_filter_factory {
46     my ($context, @args) = @_;
47     return sub {
48         my $text = shift;
49         tt_wrap($text, @args);
50     }
51 }
52
53
54 1;
55
56 __END__
57
58 =head1 NAME
59
60 Template::Plugin::Wrap - Plugin interface to Text::Wrap
61
62 =head1 SYNOPSIS
63
64     [% USE wrap %]
65     
66     # call wrap subroutine
67     [% wrap(mytext, width, initial_tab,  subsequent_tab) %]
68     
69     # or use wrap FILTER
70     [% mytext FILTER wrap(width, initital_tab, subsequent_tab) %]
71
72 =head1 DESCRIPTION
73
74 This plugin provides an interface to the L<Text::Wrap> module which 
75 provides simple paragraph formatting.
76
77 It defines a C<wrap> subroutine which can be called, passing the input
78 text and further optional parameters to specify the page width (default:
79 72), and tab characters for the first and subsequent lines (no defaults).
80
81     [% USE wrap %]
82     
83     [% text = BLOCK %]
84     First, attach the transmutex multiplier to the cross-wired 
85     quantum homogeniser.
86     [% END %]
87     
88     [% wrap(text, 40, '* ', '  ') %]
89
90 Output:
91
92     * First, attach the transmutex
93       multiplier to the cross-wired quantum
94       homogeniser.
95
96 It also registers a C<wrap> filter which accepts the same three optional 
97 arguments but takes the input text directly via the filter input.
98
99 Example 1:
100
101     [% FILTER bullet = wrap(40, '* ', '  ') -%]
102     First, attach the transmutex multiplier to the cross-wired quantum
103     homogeniser.
104     [%- END %]
105
106 Output:
107
108     * First, attach the transmutex
109       multiplier to the cross-wired quantum
110       homogeniser.
111
112 Example 2:
113
114     [% FILTER bullet -%]
115     Then remodulate the shield to match the harmonic frequency, taking 
116     care to correct the phase difference.
117     [% END %]
118
119 Output:
120
121     * Then remodulate the shield to match
122       the harmonic frequency, taking 
123       care to correct the phase difference.
124
125 =head1 AUTHOR
126
127 Andy Wardley E<lt>abw@wardley.orgE<gt> L<http://wardley.org/>
128
129 The L<Text::Wrap> module was written by David Muir Sharnoff
130 with help from Tim Pierce and many others.
131
132 =head1 COPYRIGHT
133
134 Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
135
136 This module is free software; you can redistribute it and/or
137 modify it under the same terms as Perl itself.
138
139 =head1 SEE ALSO
140
141 L<Template::Plugin>, L<Text::Wrap>
142