The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
[%#
  # IMPORTANT NOTE
  #   This documentation is generated automatically from source
  #   templates.  Any changes you make here may be lost.
  # 
  #   The 'docsrc' documentation source bundle is available for download
  #   from http://www.template-toolkit.org/docs.html and contains all
  #   the source templates, XML files, scripts, etc., from which the
  #   documentation for the Template Toolkit is built.
-%]
[% META book = 'Modules'
        page = 'Plugin_String'
%]
[%  WRAPPER toc;
	PROCESS tocitem 
	        title ="SYNOPSIS"
                subs  = [];
	PROCESS tocitem 
	        title ="DESCRIPTION"
                subs  = [];
	PROCESS tocitem 
	        title ="METHODS"
                subs  = [
                    "Construction Methods",
		    "Inspection Methods",
		    "Mutation Methods"
		];
	PROCESS tocitem 
	        title ="AUTHOR"
                subs  = [];
	PROCESS tocitem 
	        title ="VERSION"
                subs  = [];
	PROCESS tocitem 
	        title ="COPYRIGHT"
                subs  = [];
	PROCESS tocitem 
	        title ="SEE ALSO"
                subs  = [];
    END
%]
<!-- Pod to HTML conversion by the Template Toolkit version 2 -->
[% WRAPPER section
    title="SYNOPSIS"
-%]<pre>    # create String objects via USE directive
    [% tt_start_tag %] USE String [% tt_end_tag %]
    [% tt_start_tag %] USE String 'initial text' [% tt_end_tag %]
    [% tt_start_tag %] USE String text =&gt; 'initial text' [% tt_end_tag %]</pre>
<pre>    # or from an existing String via new()
    [% tt_start_tag %] newstring = String.new [% tt_end_tag %]
    [% tt_start_tag %] newstring = String.new('newstring text') [% tt_end_tag %]
    [% tt_start_tag %] newstring = String.new( text =&gt; 'newstring text' ) [% tt_end_tag %]</pre>
<pre>    # or from an existing String via copy()
    [% tt_start_tag %] newstring = String.copy [% tt_end_tag %]</pre>
<pre>    # append text to string
    [% tt_start_tag %] String.append('text to append') [% tt_end_tag %]</pre>
<pre>    # format left, right or center/centre padded
    [% tt_start_tag %] String.left(20) [% tt_end_tag %]
    [% tt_start_tag %] String.right(20) [% tt_end_tag %]
    [% tt_start_tag %] String.center(20) [% tt_end_tag %]   # American spelling
    [% tt_start_tag %] String.centre(20) [% tt_end_tag %]   # European spelling</pre>
<pre>    # and various other methods...</pre>
[%- END %]
[% WRAPPER section
    title="DESCRIPTION"
-%]<p>
This module implements a String class for doing stringy things to
text in an object-oriented way. 
</p>
<p>
You can create a String object via the USE directive, adding any 
initial text value as an argument or as the named parameter 'text'.
</p>
<pre>    [% tt_start_tag %] USE String [% tt_end_tag %]
    [% tt_start_tag %] USE String 'initial text' [% tt_end_tag %]
    [% tt_start_tag %] USE String text='initial text' [% tt_end_tag %]</pre>
<p>
The object created will be referenced as 'String' by default, but you
can provide a different variable name for the object to be assigned
to:
</p>
<pre>    [% tt_start_tag %] USE greeting = String 'Hello World' [% tt_end_tag %]</pre>
<p>
Once you've got a String object, you can use it as a prototype to 
create other String objects with the new() method.
</p>
<pre>    [% tt_start_tag %] USE String [% tt_end_tag %]
    [% tt_start_tag %] greeting = String.new('Hello World') [% tt_end_tag %]</pre>
<p>
The new() method also accepts an initial text string as an argument
or the named parameter 'text'.
</p>
<pre>    [% tt_start_tag %] greeting = String.new( text =&gt; 'Hello World' ) [% tt_end_tag %]</pre>
<p>
You can also call copy() to create a new String as a copy of the 
original.
</p>
<pre>    [% tt_start_tag %] greet2 = greeting.copy [% tt_end_tag %]</pre>
<p>
The String object has a text() method to return the content of the 
string.
</p>
<pre>    [% tt_start_tag %] greeting.text [% tt_end_tag %]</pre>
<p>
However, it is sufficient to simply print the string and let the
overloaded stringification operator call the text() method
automatically for you.
</p>
<pre>    [% tt_start_tag %] greeting [% tt_end_tag %]</pre>
<p>
Thus, you can treat String objects pretty much like any regular piece
of text, interpolating it into other strings, for example:
</p>
<pre>    [% tt_start_tag %] msg = &quot;It printed '$greeting' and then dumped core\n&quot; [% tt_end_tag %]</pre>
<p>
You also have the benefit of numerous other methods for manipulating
the string.  
</p>
<pre>    [% tt_start_tag %] msg.append(&quot;PS  Don't eat the yellow snow&quot;) [% tt_end_tag %]</pre>
<p>
Note that all methods operate on and mutate the contents of the string
itself.  If you want to operate on a copy of the string then simply
take a copy first:
</p>
<pre>    [% tt_start_tag %] msg.copy.append(&quot;PS  Don't eat the yellow snow&quot;) [% tt_end_tag %]</pre>
<p>
These methods return a reference to the String object itself.  This
allows you to chain multiple methods together.
</p>
<pre>    [% tt_start_tag %] msg.copy.append('foo').right(72) [% tt_end_tag %]</pre>
<p>
It also means that in the above examples, the String is returned which
causes the text() method to be called, which results in the new value of
the string being printed.  To suppress printing of the string, you can
use the CALL directive.
</p>
<pre>    [% tt_start_tag %] foo = String.new('foo') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] foo.append('bar') [% tt_end_tag %]         # prints &quot;foobar&quot;</pre>
<pre>    [% tt_start_tag %] CALL foo.append('bar') [% tt_end_tag %]    # nothing</pre>
[%- END %]
[% WRAPPER section
    title="METHODS"
-%][% WRAPPER subsection
   title = "Construction Methods"
-%]<p>
The following methods are used to create new String objects.
</p>
<ul>
<li><b>new()</b><br>
<p>
Creates a new string using an initial value passed as a positional
argument or the named parameter 'text'.
</p>
<pre>    [% tt_start_tag %] USE String [% tt_end_tag %]
    [% tt_start_tag %] msg = String.new('Hello World') [% tt_end_tag %]
    [% tt_start_tag %] msg = String.new( text =&gt; 'Hello World' ) [% tt_end_tag %]</pre>

<li><b>copy()</b><br>
<p>
Creates a new String object which contains a copy of the original string.
</p>
<pre>    [% tt_start_tag %] msg2 = msg.copy [% tt_end_tag %]</pre>

</ul>
[%- END %]
[% WRAPPER subsection
   title = "Inspection Methods"
-%]<p>
These methods are used to inspect the string content or other parameters
relevant to the string.
</p>
<ul>
<li><b>text()</b><br>
<p>
Returns the internal text value of the string.  The stringification
operator is overloaded to call this method.  Thus the following are
equivalent:
</p>
<pre>    [% tt_start_tag %] msg.text [% tt_end_tag %]
    [% tt_start_tag %] msg [% tt_end_tag %]</pre>

<li><b>length()</b><br>
<p>
Returns the length of the string.
</p>
<pre>    [% tt_start_tag %] USE String(&quot;foo&quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.length [% tt_end_tag %]   # =&gt; 3</pre>

<li><b>search($pattern)</b><br>
<p>
Searches the string for the regular expression specified in $pattern
returning true if found or false otherwise.
</p>
<pre>    [% tt_start_tag %] item = String.new('foo bar baz wiz waz woz') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] item.search('wiz') ? 'WIZZY! :-)' : 'not wizzy :-(' [% tt_end_tag %]</pre>

<li><b>split($pattern, $limit)</b><br>
<p>
Splits the string based on the delimiter $pattern and optional $limit.  
Delegates to Perl's internal split() so the parameters are exactly the same.
</p>
<pre>    [% tt_start_tag %] FOREACH item.split [% tt_end_tag %]
         ...
    [% tt_start_tag %] END [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] FOREACH item.split('baz|waz') [% tt_end_tag %]
         ...
    [% tt_start_tag %] END [% tt_end_tag %]</pre>

</ul>
[%- END %]
[% WRAPPER subsection
   title = "Mutation Methods"
-%]<p>
These methods modify the internal value of the string.  For example:
</p>
<pre>    [% tt_start_tag %] USE str=String('foobar') [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] str.append('.html') [% tt_end_tag %]	# str =&gt; 'foobar.html'</pre>
<p>
The value of the String 'str' is now 'foobar.html'.  If you don't want
to modify the string then simply take a copy first.
</p>
<pre>    [% tt_start_tag %] str.copy.append('.html') [% tt_end_tag %]</pre>
<p>
These methods all return a reference to the String object itself.  This
has two important benefits.  The first is that when used as above, the 
String object 'str' returned by the append() method will be stringified
with a call to its text() method.  This will return the newly modified 
string content.  In other words, a directive like:
</p>
<pre>    [% tt_start_tag %] str.append('.html') [% tt_end_tag %]</pre>
<p>
will update the string and also print the new value.  If you just want
to update the string but not print the new value then use CALL.
</p>
<pre>    [% tt_start_tag %] CALL str.append('.html') [% tt_end_tag %]</pre>
<p>
The other benefit of these methods returning a reference to the String
is that you can chain as many different method calls together as you
like.  For example:
</p>
<pre>    [% tt_start_tag %] String.append('.html').trim.format(href) [% tt_end_tag %]</pre>
<p>
Here are the methods:
</p>
<ul>
<li><b>push($suffix, ...) / append($suffix, ...)</b><br>
<p>
Appends all arguments to the end of the string.  The 
append() method is provided as an alias for push().
</p>
<pre>    [% tt_start_tag %] msg.push('foo', 'bar') [% tt_end_tag %]
    [% tt_start_tag %] msg.append('foo', 'bar') [% tt_end_tag %]</pre>

<li><b>pop($suffix)</b><br>
<p>
Removes the suffix passed as an argument from the end of the String.
</p>
<pre>    [% tt_start_tag %] USE String 'foo bar' [% tt_end_tag %]
    [% tt_start_tag %] String.pop(' bar')   [% tt_end_tag %]   # =&gt; 'foo'</pre>

<li><b>unshift($prefix, ...) / prepend($prefix, ...)</b><br>
<p>
Prepends all arguments to the beginning of the string.  The
prepend() method is provided as an alias for unshift().
</p>
<pre>    [% tt_start_tag %] msg.unshift('foo ', 'bar ') [% tt_end_tag %]
    [% tt_start_tag %] msg.prepend('foo ', 'bar ') [% tt_end_tag %]</pre>

<li><b>shift($prefix)</b><br>
<p>
Removes the prefix passed as an argument from the start of the String.
</p>
<pre>    [% tt_start_tag %] USE String 'foo bar' [% tt_end_tag %]
    [% tt_start_tag %] String.shift('foo ') [% tt_end_tag %]   # =&gt; 'bar'</pre>

<li><b>left($pad)</b><br>
<p>
If the length of the string is less than $pad then the string is left
formatted and padded with spaces to $pad length.
</p>
<pre>    [% tt_start_tag %] msg.left(20) [% tt_end_tag %]</pre>

<li><b>right($pad)</b><br>
<p>
As per left() but right padding the String to a length of $pad.
</p>
<pre>    [% tt_start_tag %] msg.right(20) [% tt_end_tag %]</pre>

<li><b>center($pad) / centre($pad)</b><br>
<p>
As per left() and right() but formatting the String to be centered within 
a space padded string of length $pad.  The centre() method is provided as 
an alias for center() to keep Yanks and Limeys happy.
</p>
<pre>    [% tt_start_tag %] msg.center(20) [% tt_end_tag %]    # American spelling
    [% tt_start_tag %] msg.centre(20) [% tt_end_tag %]    # European spelling</pre>

<li><b>format($format)</b><br>
<p>
Apply a format in the style of sprintf() to the string.
</p>
<pre>    [% tt_start_tag %] USE String(&quot;world&quot;) [% tt_end_tag %]
    [% tt_start_tag %] String.format(&quot;Hello %s\n&quot;) [% tt_end_tag %]  # =&gt; &quot;Hello World\n&quot;</pre>

<li><b>upper()</b><br>
<p>
Converts the string to upper case.
</p>
<pre>    [% tt_start_tag %] USE String(&quot;foo&quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.upper [% tt_end_tag %]  # =&gt; 'FOO'</pre>

<li><b>lower()</b><br>
<p>
Converts the string to lower case
</p>
<pre>    [% tt_start_tag %] USE String(&quot;FOO&quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.lower [% tt_end_tag %]  # =&gt; 'foo'</pre>

<li><b>capital()</b><br>
<p>
Converts the first character of the string to upper case.  
</p>
<pre>    [% tt_start_tag %] USE String(&quot;foo&quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.capital [% tt_end_tag %]  # =&gt; 'Foo'</pre>
<p>
The remainder of the string is left untouched.  To force the string to
be all lower case with only the first letter capitalised, you can do 
something like this:
</p>
<pre>    [% tt_start_tag %] USE String(&quot;FOO&quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.lower.capital [% tt_end_tag %]  # =&gt; 'Foo'</pre>

<li><b>chop()</b><br>
<p>
Removes the last character from the string.
</p>
<pre>    [% tt_start_tag %] USE String(&quot;foop&quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.chop [% tt_end_tag %]	# =&gt; 'foo'</pre>

<li><b>chomp()</b><br>
<p>
Removes the trailing newline from the string.
</p>
<pre>    [% tt_start_tag %] USE String(&quot;foo\n&quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.chomp [% tt_end_tag %]	# =&gt; 'foo'</pre>

<li><b>trim()</b><br>
<p>
Removes all leading and trailing whitespace from the string
</p>
<pre>    [% tt_start_tag %] USE String(&quot;   foo   \n\n &quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.trim [% tt_end_tag %]	# =&gt; 'foo'</pre>

<li><b>collapse()</b><br>
<p>
Removes all leading and trailing whitespace and collapses any sequences
of multiple whitespace to a single space.
</p>
<pre>    [% tt_start_tag %] USE String(&quot; \n\r  \t  foo   \n \n bar  \n&quot;) [% tt_end_tag %]</pre>
<pre>    [% tt_start_tag %] String.collapse [% tt_end_tag %]   # =&gt; &quot;foo bar&quot;</pre>

<li><b>truncate($length, $suffix)</b><br>
<p>
Truncates the string to $length characters.
</p>
<pre>    [% tt_start_tag %] USE String('long string') [% tt_end_tag %]
    [% tt_start_tag %] String.truncate(4) [% tt_end_tag %]  # =&gt; 'long'</pre>
<p>
If $suffix is specified then it will be appended to the truncated
string.  In this case, the string will be further shortened by the 
length of the suffix to ensure that the newly constructed string
complete with suffix is exactly $length characters long.
</p>
<pre>    [% tt_start_tag %] USE msg = String('Hello World') [% tt_end_tag %]
    [% tt_start_tag %] msg.truncate(8, '...') [% tt_end_tag %]   # =&gt; 'Hello...'</pre>

<li><b>replace($search, $replace)</b><br>
<p>
Replaces all occurences of $search in the string with $replace.
</p>
<pre>    [% tt_start_tag %] USE String('foo bar foo baz') [% tt_end_tag %]
    [% tt_start_tag %] String.replace('foo', 'wiz')  [% tt_end_tag %]  # =&gt; 'wiz bar wiz baz'</pre>

<li><b>remove($search)</b><br>
<p>
Remove all occurences of $search in the string.
</p>
<pre>    [% tt_start_tag %] USE String('foo bar foo baz') [% tt_end_tag %]
    [% tt_start_tag %] String.remove('foo ')  [% tt_end_tag %]  # =&gt; 'bar baz'</pre>

<li><b>repeat($count)</b><br>
<p>
Repeats the string $count times.
</p>
<pre>    [% tt_start_tag %] USE String('foo ') [% tt_end_tag %]
    [% tt_start_tag %] String.repeat(3)  [% tt_end_tag %]  # =&gt; 'foo foo foo '</pre>

</ul>
[%- END %]
[%- END %]
[% WRAPPER section
    title="AUTHOR"
-%]<p>
Andy Wardley &lt;abw@andywardley.com&gt;
</p>
<p>
[% ttlink('http://www.andywardley.com/', 'http://www.andywardley.com/') -%]
</p>
[%- END %]
[% WRAPPER section
    title="VERSION"
-%]<p>
2.20, distributed as part of the
Template Toolkit version 2.08, released on 30 July 2002.
</p>
[%- END %]
[% WRAPPER section
    title="COPYRIGHT"
-%]<pre>  Copyright (C) 1996-2002 Andy Wardley.  All Rights Reserved.
  Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.</pre>
<p>
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
</p>
[%- END %]
[% WRAPPER section
    title="SEE ALSO"
-%]<p>
[% ttlink('Template::Plugin', 'Template::Plugin') -%]
</p>
[%- END %]