1 #============================================================= -*-Perl-*-
3 # Template::Plugin::Wrap
6 # Plugin for wrapping text via the Text::Wrap module.
9 # Andy Wardley <abw@wardley.org>
12 # Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
14 # This module is free software; you can redistribute it and/or
15 # modify it under the same terms as Perl itself.
17 #============================================================================
19 package Template::Plugin::Wrap;
23 use base 'Template::Plugin';
29 my ($class, $context, $format) = @_;;
30 $context->define_filter('wrap', [ \&wrap_filter_factory => 1 ]);
36 my $width = shift || 72;
39 $itab = '' unless defined $itab;
40 $ntab = '' unless defined $ntab;
41 $Text::Wrap::columns = $width;
42 Text::Wrap::wrap($itab, $ntab, $text);
45 sub wrap_filter_factory {
46 my ($context, @args) = @_;
49 tt_wrap($text, @args);
60 Template::Plugin::Wrap - Plugin interface to Text::Wrap
66 # call wrap subroutine
67 [% wrap(mytext, width, initial_tab, subsequent_tab) %]
70 [% mytext FILTER wrap(width, initital_tab, subsequent_tab) %]
74 This plugin provides an interface to the L<Text::Wrap> module which
75 provides simple paragraph formatting.
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).
84 First, attach the transmutex multiplier to the cross-wired
88 [% wrap(text, 40, '* ', ' ') %]
92 * First, attach the transmutex
93 multiplier to the cross-wired quantum
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.
101 [% FILTER bullet = wrap(40, '* ', ' ') -%]
102 First, attach the transmutex multiplier to the cross-wired quantum
108 * First, attach the transmutex
109 multiplier to the cross-wired quantum
115 Then remodulate the shield to match the harmonic frequency, taking
116 care to correct the phase difference.
121 * Then remodulate the shield to match
122 the harmonic frequency, taking
123 care to correct the phase difference.
127 Andy Wardley E<lt>abw@wardley.orgE<gt> L<http://wardley.org/>
129 The L<Text::Wrap> module was written by David Muir Sharnoff
130 with help from Tim Pierce and many others.
134 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
136 This module is free software; you can redistribute it and/or
137 modify it under the same terms as Perl itself.
141 L<Template::Plugin>, L<Text::Wrap>