.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "String::BufferStack 3pm" .TH String::BufferStack 3pm "2010-01-06" "perl v5.10.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" String::BufferStack \- Nested buffers for templating systems .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& my $stack = String::BufferStack\->new; \& $stack\->push( filter => sub {return uc shift} ); \& $stack\->append("content"); \& $stack\->flush_output; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`String::BufferStack\*(C'\fR provides a framework for storing nested buffers. By default, all of the buffers flow directly to the output method, but individual levels of the stack can apply filters, or store their output in a scalar reference. .SH "METHODS" .IX Header "METHODS" .SS "new \s-1PARAMHASH\s0" .IX Subsection "new PARAMHASH" Creates a new buffer stack and returns it. Possible arguments include: .IP "prealoc" 4 .IX Item "prealoc" Preallocate this many bytes in the output buffer. This can reduce reallocations, and thus speed up appends. .IP "out_method" 4 .IX Item "out_method" The method to call when output trickles down to the bottom-most buffer and is flushed via flush_output. The default \f(CW\*(C`out_method\*(C'\fR prints the content to \f(CW\*(C`STDOUT\*(C'\fR. This method will always be called with non-undef, non-zero length content. .IP "use_length" 4 .IX Item "use_length" Calculate length of each buffer as it is built. This imposes a significant runtime cost, so should be avoided if at all possible. Defaults to off. .SS "push \s-1PARAMHASH\s0" .IX Subsection "push PARAMHASH" Pushes a new frame onto the buffer stack. By default, the output from this new frame connects to the input of the previous frame. There are a number of possible options: .IP "buffer" 4 .IX Item "buffer" A string reference, into which the output from this stack frame will appear. By default, this is the input buffer of the previous frame. .IP "private" 4 .IX Item "private" If a true value is passed for \f(CW\*(C`private\*(C'\fR, it creates a private string reference, and uses that as the buffer \*(-- this is purely for convenience. That is, the following blocks are equivilent: .Sp .Vb 5 \& my $buffer = ""; \& $stack\->push( buffer => \e$buffer ); \& # ... \& $stack\->pop; \& print $buffer; \& \& $stack\->push( private => 1 ); \& # ... \& print $stack\->pop; .Ve .IP "pre_append" 4 .IX Item "pre_append" A callback, which will be called with a reference to the \&\f(CW\*(C`String::BufferStack\*(C'\fR object, and the arguments to append, whenever this stack frame has anything appended to the input buffer, directly or indirectly. .Sp Within the context of the pre-append callback, \*(L"append\*(R", \&\*(L"direct_append\*(R", and \*(L"set_pre_append\*(R" function on the frame the pre-append is attached to, not the topmost trame. Using \*(L"append\*(R" within the pre-append callback is not suggested; use \&\*(L"direct_append\*(R" instead. \*(L"set_pre_append\*(R" can be used to alter or remove the pre-append callback itself \*(-- this is not uncommon, in the case where the first append is the only one which needs be watched for, for instance. .IP "filter" 4 .IX Item "filter" A callback, used to process data which is appended to the stack frame. By default, filters are lazy, being called only when a frame is popped. They can be forced at any time by calling \*(L"flush_filters\*(R", however. .SS "depth" .IX Subsection "depth" Returns the current depth of the stack. This starts at 0, when no frames have been pushed, and increases by one for each frame pushed. .SS "append \s-1STRING\s0 [, \s-1STRING\s0, ...]" .IX Subsection "append STRING [, STRING, ...]" Appends the given strings to the input side of the topmost buffer. This will call all pre-append hooks attached to it, as well. Note that if the frame has a filter, the filter will not immediately run, but will be delayed until the frame is \*(L"pop\*(R"'d, or \*(L"flush_filters\*(R" is called. .PP When called with no frames on the stack, appends the stringins directly to the \*(L"output_buffer\*(R". .SS "direct_append \s-1STRING\s0 [, \s-1STRING\s0, ...]" .IX Subsection "direct_append STRING [, STRING, ...]" Similar to \*(L"append\*(R", but appends the strings to the output side of the frame, skipping pre-append callbacks and filters. .PP When called with no frames on the stack, appends the strings directly to the \*(L"output_buffer\*(R". .SS "pop" .IX Subsection "pop" Removes the topmost frame on the stack, flushing the topmost filters in the process. Returns the output buffer of the frame \*(-- note that this may not contain only strings appended in the current frame, but also those from before, as a speed optimization. That is: .PP .Vb 4 \& $stack\->append("one"); \& $stack\->push; \& $stack\->append(" two"); \& $stack\->pop; # returns "one two" .Ve .PP This operation is a no-op if there are no frames on the stack. .SS "set_pre_append \s-1CALLBACK\s0" .IX Subsection "set_pre_append CALLBACK" Alters the pre-append callback on the topmost frame. The callback will be called before text is appended to the input buffer of the frame, and will be passed the \f(CW\*(C`String::BufferStack\*(C'\fR and the arguments to \*(L"append\*(R". .SS "set_filter \s-1FILTER\s0" .IX Subsection "set_filter FILTER" Alters the filter on the topmost frame. Doing this flushes the filters on the topmost frame. .SS "filter" .IX Subsection "filter" Filters the topmost stack frame, if it has outstanding unfiltered data. This will propagate content to lower frames, possibly calling their pre-append hooks. .SS "flush" .IX Subsection "flush" If there are no frames on the stack, calls \*(L"flush_output\*(R". Otherwise, calls \*(L"flush_filters\*(R". .SS "flush_filters" .IX Subsection "flush_filters" Flushes all filters. This does not flush output from the output buffer; see \*(L"flush_output\*(R". .SS "buffer" .IX Subsection "buffer" Returns the contents of the output buffer of the topmost frame; if there are no frames, returns the output buffer. .SS "buffer_ref" .IX Subsection "buffer_ref" Returns a reference to the output buffer of the topmost frame; if there are no frames, returns a reference to the output buffer. Note that adjusting this skips pre-append and filter hooks. .SS "length" .IX Subsection "length" If \f(CW\*(C`use_length\*(C'\fR was enabled in the buffer stack's constructor, returns the number of characters appended to the current frame; if there are no frames, returns the length of the output buffer. .PP If \f(CW\*(C`use_length\*(C'\fR was not enabled, warns and returns 0. .SS "flush_output" .IX Subsection "flush_output" Flushes all filters using \*(L"flush_filters\*(R", then flushes output from the output buffer, using the configured \*(L"out_method\*(R". .SS "output_buffer" .IX Subsection "output_buffer" Returns the pending output buffer, which sits below all existing frames. .SS "output_buffer_ref" .IX Subsection "output_buffer_ref" Returns a reference to the pending output buffer, allowing you to modify it. .SS "clear" .IX Subsection "clear" Clears \fIall\fR buffers in the stack, including the output buffer. .SS "clear_top" .IX Subsection "clear_top" Clears the topmost buffer in the stack; if there are no frames on the stack, clears the output buffer. .SS "out_method [\s-1CALLBACK\s0]" .IX Subsection "out_method [CALLBACK]" Gets or sets the output method callback, which is given content from the pending output buffer, which sits below all frames. .SH "SEE ALSO" .IX Header "SEE ALSO" Many concepts were originally taken from HTML::Mason's internal buffer stack. .SH "AUTHORS" .IX Header "AUTHORS" Alex Vandiver \f(CW\*(C`alexmv@bestpractical.com\*(C'\fR .SH "LICENSE" .IX Header "LICENSE" Copyright 2008\-2009, Best Practical Solutions. .PP This package is distributed under the same terms as Perl itself.