.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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" '' . ds C` . ds C' '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 >0, 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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Template::Plugin::DateTime::Format 3pm" .TH Template::Plugin::DateTime::Format 3pm "2021-01-08" "perl v5.32.0" "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" Template::Plugin::DateTime::Format \- format DateTime objects from inside TT with DateTime::Format\-style formatters .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& [% USE f = DateTime::Format(\*(AqDateTime::Format::Strptime\*(Aq, { pattern => "%T" }) %] \& [% f.format(datetime_object) %] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Oftentimes, you have a DateTime object that you want to render in your template. However, the default rendering (2008\-01\-01T01:23:45) is pretty ugly. Formatting the DateTime with a DateTime::Format object is the usual solution, but there's usually not a nice place to put the formatting code. .PP This plugin solves that problem. You can create a formatter object from within \s-1TT\s0 and then use that object to format DateTime objects. .SS "\s-1CREATING AN OBJECT\s0" .IX Subsection "CREATING AN OBJECT" Creating a formatter instance is done in the usual \s-1TT\s0 way: .PP .Vb 1 \& [% USE varname = DateTime::Format( ... args ... ) %] .Ve .PP This creates a new formatter and calls it \f(CW\*(C`varname\*(C'\fR. .PP The constructor takes up to three arguments. The first argument is the name of the formatter class. It is required, and the named class must follow the DateTime::Format \s-1API.\s0 An exception will be thrown if the class cannot be loaded. .PP The second argument is a reference to pass to the formatter's constructor. If it is an array reference, the array will be dereferenced before being passed to \f(CW\*(C`new\*(C'\fR as \f(CW@_\fR. Otherwise, the single reference is passed to the constructor. .PP The third argument is optional and is the rest of \f(CW@_\fR to pass to \&\f(CW\*(C`format_datetime\*(C'\fR after the DateTime object. I don't know if this is actually allowed by the \s-1API,\s0 but I figured it might come in handy. .SS "\s-1FORMATTING DATES\s0" .IX Subsection "FORMATTING DATES" Once you've created the object, invoke the \f(CW\*(C`format\*(C'\fR method with the DateTime object you'd like to format. The result of \&\f(CW\*(C`format_datetime\*(C'\fR is returned. .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Called by \s-1TT\s0 to create a new formatter. .SS "format($datetime)" .IX Subsection "format($datetime)" Formats \f(CW$datetime\fR. .SH "REPOSITORY" .IX Header "REPOSITORY" .SH "AUTHOR" .IX Header "AUTHOR" Jonathan Rockway \f(CW\*(C`\*(C'\fR .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (c) 2008 Jonathan Rockway. .PP This module is free software. You may redistribute it under the same terms as perl itself.