Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Template::Plugin::String.3pm
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sh \" Subsection heading
6 .br
7 .if t .Sp
8 .ne 5
9 .PP
10 \fB\\$1\fR
11 .PP
12 ..
13 .de Sp \" Vertical space (when we can't use .PP)
14 .if t .sp .5v
15 .if n .sp
16 ..
17 .de Vb \" Begin verbatim text
18 .ft CW
19 .nf
20 .ne \\$1
21 ..
22 .de Ve \" End verbatim text
23 .ft R
24 .fi
25 ..
26 .\" Set up some character translations and predefined strings.  \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote.  | will give a
29 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
32 .tr \(*W-|\(bv\*(Tr
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34 .ie n \{\
35 .    ds -- \(*W-
36 .    ds PI pi
37 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
39 .    ds L" ""
40 .    ds R" ""
41 .    ds C` ""
42 .    ds C' ""
43 'br\}
44 .el\{\
45 .    ds -- \|\(em\|
46 .    ds PI \(*p
47 .    ds L" ``
48 .    ds R" ''
49 'br\}
50 .\"
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD.  Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
55 .if \nF \{\
56 .    de IX
57 .    tm Index:\\$1\t\\n%\t"\\$2"
58 ..
59 .    nr % 0
60 .    rr F
61 .\}
62 .\"
63 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
65 .hy 0
66 .if n .na
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "Template::Plugin::String 3"
132 .TH Template::Plugin::String 3 "2008-11-13" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 Template::Plugin::String \- Object oriented interface for string manipulation
135 .SH "SYNOPSIS"
136 .IX Header "SYNOPSIS"
137 .Vb 4
138 \&    # create String objects via USE directive
139 \&    [% USE String %]
140 \&    [% USE String 'initial text' %]
141 \&    [% USE String text => 'initial text' %]
142 .Ve
143 .PP
144 .Vb 4
145 \&    # or from an existing String via new()
146 \&    [% newstring = String.new %]
147 \&    [% newstring = String.new('newstring text') %]
148 \&    [% newstring = String.new( text => 'newstring text' ) %]
149 .Ve
150 .PP
151 .Vb 2
152 \&    # or from an existing String via copy()
153 \&    [% newstring = String.copy %]
154 .Ve
155 .PP
156 .Vb 2
157 \&    # append text to string
158 \&    [% String.append('text to append') %]
159 .Ve
160 .PP
161 .Vb 5
162 \&    # format left, right or center/centre padded
163 \&    [% String.left(20) %]
164 \&    [% String.right(20) %]
165 \&    [% String.center(20) %]   # American spelling
166 \&    [% String.centre(20) %]   # European spelling
167 .Ve
168 .PP
169 .Vb 1
170 \&    # and various other methods...
171 .Ve
172 .SH "DESCRIPTION"
173 .IX Header "DESCRIPTION"
174 This module implements a \f(CW\*(C`String\*(C'\fR class for doing stringy things to
175 text in an object-oriented way. 
176 .PP
177 You can create a \f(CW\*(C`String\*(C'\fR object via the \f(CW\*(C`USE\*(C'\fR directive, adding any 
178 initial text value as an argument or as the named parameter \f(CW\*(C`text\*(C'\fR.
179 .PP
180 .Vb 3
181 \&    [% USE String %]
182 \&    [% USE String 'initial text' %]
183 \&    [% USE String text='initial text' %]
184 .Ve
185 .PP
186 The object created will be referenced as \f(CW\*(C`String\*(C'\fR by default, but you
187 can provide a different variable name for the object to be assigned
188 to:
189 .PP
190 .Vb 1
191 \&    [% USE greeting = String 'Hello World' %]
192 .Ve
193 .PP
194 Once you've got a \f(CW\*(C`String\*(C'\fR object, you can use it as a prototype to 
195 create other \f(CW\*(C`String\*(C'\fR objects with the \f(CW\*(C`new()\*(C'\fR method.
196 .PP
197 .Vb 2
198 \&    [% USE String %]
199 \&    [% greeting = String.new('Hello World') %]
200 .Ve
201 .PP
202 The \f(CW\*(C`new()\*(C'\fR method also accepts an initial text string as an argument
203 or the named parameter \f(CW\*(C`text\*(C'\fR.
204 .PP
205 .Vb 1
206 \&    [% greeting = String.new( text => 'Hello World' ) %]
207 .Ve
208 .PP
209 You can also call \f(CW\*(C`copy()\*(C'\fR to create a new \f(CW\*(C`String\*(C'\fR as a copy of the 
210 original.
211 .PP
212 .Vb 1
213 \&    [% greet2 = greeting.copy %]
214 .Ve
215 .PP
216 The \f(CW\*(C`String\*(C'\fR object has a \f(CW\*(C`text()\*(C'\fR method to return the content of the 
217 string.
218 .PP
219 .Vb 1
220 \&    [% greeting.text %]
221 .Ve
222 .PP
223 However, it is sufficient to simply print the string and let the
224 overloaded stringification operator call the \f(CW\*(C`text()\*(C'\fR method
225 automatically for you.
226 .PP
227 .Vb 1
228 \&    [% greeting %]
229 .Ve
230 .PP
231 Thus, you can treat \f(CW\*(C`String\*(C'\fR objects pretty much like any regular piece
232 of text, interpolating it into other strings, for example:
233 .PP
234 .Vb 1
235 \&    [% msg = "It printed '$greeting' and then dumped core\en" %]
236 .Ve
237 .PP
238 You also have the benefit of numerous other methods for manipulating
239 the string.  
240 .PP
241 .Vb 1
242 \&    [% msg.append("PS  Don't eat the yellow snow") %]
243 .Ve
244 .PP
245 Note that all methods operate on and mutate the contents of the string
246 itself.  If you want to operate on a copy of the string then simply
247 take a copy first:
248 .PP
249 .Vb 1
250 \&    [% msg.copy.append("PS  Don't eat the yellow snow") %]
251 .Ve
252 .PP
253 These methods return a reference to the \f(CW\*(C`String\*(C'\fR object itself.  This
254 allows you to chain multiple methods together.
255 .PP
256 .Vb 1
257 \&    [% msg.copy.append('foo').right(72) %]
258 .Ve
259 .PP
260 It also means that in the above examples, the \f(CW\*(C`String\*(C'\fR is returned which
261 causes the \f(CW\*(C`text()\*(C'\fR method to be called, which results in the new value of
262 the string being printed.  To suppress printing of the string, you can
263 use the \f(CW\*(C`CALL\*(C'\fR directive.
264 .PP
265 .Vb 1
266 \&    [% foo = String.new('foo') %]
267 .Ve
268 .PP
269 .Vb 1
270 \&    [% foo.append('bar') %]         # prints "foobar"
271 .Ve
272 .PP
273 .Vb 1
274 \&    [% CALL foo.append('bar') %]    # nothing
275 .Ve
276 .SH "CONSTRUCTOR METHODS"
277 .IX Header "CONSTRUCTOR METHODS"
278 These methods are used to create new \f(CW\*(C`String\*(C'\fR objects.
279 .Sh "\fInew()\fP"
280 .IX Subsection "new()"
281 Creates a new string using an initial value passed as a positional
282 argument or the named parameter \f(CW\*(C`text\*(C'\fR.
283 .PP
284 .Vb 3
285 \&    [% USE String %]
286 \&    [% msg = String.new('Hello World') %]
287 \&    [% msg = String.new( text => 'Hello World' ) %]
288 .Ve
289 .Sh "\fIcopy()\fP"
290 .IX Subsection "copy()"
291 Creates a new \f(CW\*(C`String\*(C'\fR object which contains a copy of the original string.
292 .PP
293 .Vb 1
294 \&    [% msg2 = msg.copy %]
295 .Ve
296 .SH "INSPECTOR METHODS"
297 .IX Header "INSPECTOR METHODS"
298 These methods are used to examine the string.
299 .Sh "\fItext()\fP"
300 .IX Subsection "text()"
301 Returns the internal text value of the string.  The stringification
302 operator is overloaded to call this method.  Thus the following are
303 equivalent:
304 .PP
305 .Vb 2
306 \&    [% msg.text %]
307 \&    [% msg %]
308 .Ve
309 .Sh "\fIlength()\fP"
310 .IX Subsection "length()"
311 Returns the length of the string.
312 .PP
313 .Vb 2
314 \&    [% USE String("foo") %]
315 \&    [% String.length %]   # => 3
316 .Ve
317 .Sh "search($pattern)"
318 .IX Subsection "search($pattern)"
319 Searches the string for the regular expression specified in \f(CW$pattern\fR
320 returning true if found or false otherwise.
321 .PP
322 .Vb 2
323 \&    [% item = String.new('foo bar baz wiz waz woz') %]
324 \&    [% item.search('wiz') ? 'WIZZY! :\-)' : 'not wizzy :\-(' %]
325 .Ve
326 .ie n .Sh "split($pattern, $limit)"
327 .el .Sh "split($pattern, \f(CW$limit\fP)"
328 .IX Subsection "split($pattern, $limit)"
329 Splits the string based on the delimiter \f(CW$pattern\fR and optional \f(CW$limit\fR.
330 Delegates to Perl's internal \f(CW\*(C`split()\*(C'\fR so the parameters are exactly the same.
331 .PP
332 .Vb 3
333 \&    [% FOREACH item.split %]
334 \&         ...
335 \&    [% END %]
336 .Ve
337 .PP
338 .Vb 3
339 \&    [% FOREACH item.split('baz|waz') %]
340 \&         ...
341 \&    [% END %]
342 .Ve
343 .SH "MUTATOR METHODS"
344 .IX Header "MUTATOR METHODS"
345 These methods modify the internal value of the string.  For example:
346 .PP
347 .Vb 2
348 \&    [% USE str=String('foobar') %]
349 \&    [% str.append('.html') %]   # str => 'foobar.html'
350 .Ve
351 .PP
352 The value of \f(CW\*(C`str\*(C'\fR is now '\f(CW\*(C`foobar.html\*(C'\fR'.  If you don't want
353 to modify the string then simply take a copy first.
354 .PP
355 .Vb 1
356 \&    [% str.copy.append('.html') %]
357 .Ve
358 .PP
359 These methods all return a reference to the \f(CW\*(C`String\*(C'\fR object itself.  This
360 has two important benefits.  The first is that when used as above, the 
361 \&\f(CW\*(C`String\*(C'\fR object '\f(CW\*(C`str\*(C'\fR' returned by the \f(CW\*(C`append()\*(C'\fR method will be stringified
362 with a call to its \f(CW\*(C`text()\*(C'\fR method.  This will return the newly modified 
363 string content.  In other words, a directive like:
364 .PP
365 .Vb 1
366 \&    [% str.append('.html') %]
367 .Ve
368 .PP
369 will update the string and also print the new value.  If you just want
370 to update the string but not print the new value then use \f(CW\*(C`CALL\*(C'\fR.
371 .PP
372 .Vb 1
373 \&    [% CALL str.append('.html') %]
374 .Ve
375 .PP
376 The other benefit of these methods returning a reference to the \f(CW\*(C`String\*(C'\fR
377 is that you can chain as many different method calls together as you
378 like.  For example:
379 .PP
380 .Vb 1
381 \&    [% String.append('.html').trim.format(href) %]
382 .Ve
383 .PP
384 Here are the methods:
385 .Sh "push($suffix, ...) / append($suffix, ...)"
386 .IX Subsection "push($suffix, ...) / append($suffix, ...)"
387 Appends all arguments to the end of the string.  The 
388 \&\f(CW\*(C`append()\*(C'\fR method is provided as an alias for \f(CW\*(C`push()\*(C'\fR.
389 .PP
390 .Vb 2
391 \&    [% msg.push('foo', 'bar') %]
392 \&    [% msg.append('foo', 'bar') %]
393 .Ve
394 .Sh "pop($suffix)"
395 .IX Subsection "pop($suffix)"
396 Removes the suffix passed as an argument from the end of the String.
397 .PP
398 .Vb 2
399 \&    [% USE String 'foo bar' %]
400 \&    [% String.pop(' bar')   %]   # => 'foo'
401 .Ve
402 .Sh "unshift($prefix, ...) / prepend($prefix, ...)"
403 .IX Subsection "unshift($prefix, ...) / prepend($prefix, ...)"
404 Prepends all arguments to the beginning of the string.  The
405 \&\f(CW\*(C`prepend()\*(C'\fR method is provided as an alias for \f(CW\*(C`unshift()\*(C'\fR.
406 .PP
407 .Vb 2
408 \&    [% msg.unshift('foo ', 'bar ') %]
409 \&    [% msg.prepend('foo ', 'bar ') %]
410 .Ve
411 .Sh "shift($prefix)"
412 .IX Subsection "shift($prefix)"
413 Removes the prefix passed as an argument from the start of the String.
414 .PP
415 .Vb 2
416 \&    [% USE String 'foo bar' %]
417 \&    [% String.shift('foo ') %]   # => 'bar'
418 .Ve
419 .Sh "left($pad)"
420 .IX Subsection "left($pad)"
421 If the length of the string is less than \f(CW$pad\fR then the string is left
422 formatted and padded with spaces to \f(CW$pad\fR length.
423 .PP
424 .Vb 1
425 \&    [% msg.left(20) %]
426 .Ve
427 .Sh "right($pad)"
428 .IX Subsection "right($pad)"
429 As per \fIleft()\fR but right padding the \f(CW\*(C`String\*(C'\fR to a length of \f(CW$pad\fR.
430 .PP
431 .Vb 1
432 \&    [% msg.right(20) %]
433 .Ve
434 .Sh "center($pad) / centre($pad)"
435 .IX Subsection "center($pad) / centre($pad)"
436 As per \fIleft()\fR and \fIright()\fR but formatting the \f(CW\*(C`String\*(C'\fR to be centered within 
437 a space padded string of length \f(CW$pad\fR.  The \f(CW\*(C`centre()\*(C'\fR method is provided as 
438 an alias for \f(CW\*(C`center()\*(C'\fR.
439 .PP
440 .Vb 2
441 \&    [% msg.center(20) %]    # American spelling
442 \&    [% msg.centre(20) %]    # European spelling
443 .Ve
444 .Sh "format($format)"
445 .IX Subsection "format($format)"
446 Apply a format in the style of \f(CW\*(C`sprintf()\*(C'\fR to the string.
447 .PP
448 .Vb 2
449 \&    [% USE String("world") %]
450 \&    [% String.format("Hello %s\en") %]  # => "Hello World\en"
451 .Ve
452 .Sh "\fIupper()\fP"
453 .IX Subsection "upper()"
454 Converts the string to upper case.
455 .PP
456 .Vb 2
457 \&    [% USE String("foo") %]
458 \&    [% String.upper %]  # => 'FOO'
459 .Ve
460 .Sh "\fIlower()\fP"
461 .IX Subsection "lower()"
462 Converts the string to lower case
463 .PP
464 .Vb 2
465 \&    [% USE String("FOO") %]
466 \&    [% String.lower %]  # => 'foo'
467 .Ve
468 .Sh "\fIcapital()\fP"
469 .IX Subsection "capital()"
470 Converts the first character of the string to upper case.  
471 .PP
472 .Vb 2
473 \&    [% USE String("foo") %]
474 \&    [% String.capital %]  # => 'Foo'
475 .Ve
476 .PP
477 The remainder of the string is left untouched.  To force the string to
478 be all lower case with only the first letter capitalised, you can do 
479 something like this:
480 .PP
481 .Vb 2
482 \&    [% USE String("FOO") %]
483 \&    [% String.lower.capital %]  # => 'Foo'
484 .Ve
485 .Sh "\fIchop()\fP"
486 .IX Subsection "chop()"
487 Removes the last character from the string.
488 .PP
489 .Vb 2
490 \&    [% USE String("foop") %]
491 \&    [% String.chop %]   # => 'foo'
492 .Ve
493 .Sh "\fIchomp()\fP"
494 .IX Subsection "chomp()"
495 Removes the trailing newline from the string.
496 .PP
497 .Vb 2
498 \&    [% USE String("foo\en") %]
499 \&    [% String.chomp %]  # => 'foo'
500 .Ve
501 .Sh "\fItrim()\fP"
502 .IX Subsection "trim()"
503 Removes all leading and trailing whitespace from the string
504 .PP
505 .Vb 2
506 \&    [% USE String("   foo   \en\en ") %]
507 \&    [% String.trim %]   # => 'foo'
508 .Ve
509 .Sh "\fIcollapse()\fP"
510 .IX Subsection "collapse()"
511 Removes all leading and trailing whitespace and collapses any sequences
512 of multiple whitespace to a single space.
513 .PP
514 .Vb 2
515 \&    [% USE String(" \en\er  \et  foo   \en \en bar  \en") %]
516 \&    [% String.collapse %]   # => "foo bar"
517 .Ve
518 .ie n .Sh "truncate($length, $suffix)"
519 .el .Sh "truncate($length, \f(CW$suffix\fP)"
520 .IX Subsection "truncate($length, $suffix)"
521 Truncates the string to \f(CW$length\fR characters.
522 .PP
523 .Vb 2
524 \&    [% USE String('long string') %]
525 \&    [% String.truncate(4) %]  # => 'long'
526 .Ve
527 .PP
528 If \f(CW$suffix\fR is specified then it will be appended to the truncated
529 string.  In this case, the string will be further shortened by the 
530 length of the suffix to ensure that the newly constructed string
531 complete with suffix is exactly \f(CW$length\fR characters long.
532 .PP
533 .Vb 2
534 \&    [% USE msg = String('Hello World') %]
535 \&    [% msg.truncate(8, '...') %]   # => 'Hello...'
536 .Ve
537 .ie n .Sh "replace($search, $replace)"
538 .el .Sh "replace($search, \f(CW$replace\fP)"
539 .IX Subsection "replace($search, $replace)"
540 Replaces all occurences of \f(CW$search\fR in the string with \f(CW$replace\fR.
541 .PP
542 .Vb 2
543 \&    [% USE String('foo bar foo baz') %]
544 \&    [% String.replace('foo', 'wiz')  %]  # => 'wiz bar wiz baz'
545 .Ve
546 .Sh "remove($search)"
547 .IX Subsection "remove($search)"
548 Remove all occurences of \f(CW$search\fR in the string.
549 .PP
550 .Vb 2
551 \&    [% USE String('foo bar foo baz') %]
552 \&    [% String.remove('foo ')  %]  # => 'bar baz'
553 .Ve
554 .Sh "repeat($count)"
555 .IX Subsection "repeat($count)"
556 Repeats the string \f(CW$count\fR times.
557 .PP
558 .Vb 2
559 \&    [% USE String('foo ') %]
560 \&    [% String.repeat(3)  %]  # => 'foo foo foo '
561 .Ve
562 .SH "AUTHOR"
563 .IX Header "AUTHOR"
564 Andy Wardley <abw@wardley.org> <http://wardley.org/>
565 .SH "COPYRIGHT"
566 .IX Header "COPYRIGHT"
567 Copyright (C) 1996\-2007 Andy Wardley.  All Rights Reserved.
568 .PP
569 This module is free software; you can redistribute it and/or
570 modify it under the same terms as Perl itself.
571 .SH "SEE ALSO"
572 .IX Header "SEE ALSO"
573 Template::Plugin