Tenjin::Util(3pm)
π NAME π
okay so bestie, this page is all about <pink>Tenjin::Util</pink> π β it's documented as part of the User Contributed Perl Documentation, and it's literally just utility methods for Tenjin. that's the whole vibe. no cap.
β¨ SYNOPSIS β¨
like, in your templates, bestie:
# in your templates:
# encode a URL
[== encode_url('http://www.google.com/search?q=tenjin&ie=utf-8&oe=utf-8&aq=t') =]
# returns http%3A//www.google.com/search%3Fq%3Dtenjin%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt
# escape a string of lines of HTML code
<?pl my $string = '<h1>You & Me</h1>\n<h2>Me & You</h2>'; ?>
[== text2html($string) =]
# returns <h1>You & Me</h1><br />\n<h2>Me & You</h2>
π DESCRIPTION π
so this module gives you a lil handful of utility functions you can use in your templates, purely for your convenience π«Ά. the lineup is the (un)escape squad and the (en/de)code URLs squad. that's it. that's the whole package. iconic.
πΈ METHODS πΈ
β¨ expand_tabs( $str, [$tabwidth] ) β¨
you hand it a string that might have tabs hiding in it, and it swaps those tabs out for spaces π
. each tab becomes the number of spaces defined by $tabwidth β or, if you didn't pass $tabwidth at all, each tab becomes 8 spaces. default behaviour, slay.
β¨ escape_xml( $str ) β¨
give it a string of XML (or (x)HTML) code and it converts the characters <>&\' into HTML entities π§. this is THE method that gets invoked when you use [= $expression =] in your templates. so like, that's the one doing the work behind the scenes. main character energy, fr.
β¨ unescape_xml( $str ) β¨
the glow-up in reverse π« β give it a string of escaped XML (or (x)HTML) code (say, something that got escaped by the escape_xml() function) and it 'unescapes' every HTML entity back to its actual character. undoing the damage. we love a redemption arc.
β¨ encode_url( $url ) β¨
hand it a URL and it encodes it by escaping the 'non-standard' characters π¦.
β¨ decode_url( $url ) β¨
literally does the opposite of encode_url(). that's the whole description. it's giving mirror twin π
.
β¨ checked( $val ) β¨
you pass it a value of some sort, and if that value is true, it returns the string ' checked="checked"' β which you can append to HTML checkboxes β
. yes the leading space is part of the string. do not come for it.
β¨ selected( $val ) β¨
same energy: pass a value of some sort, and if it's true, you get back the string ' selected="selected"', which you can drop into an option inside an HTML select box π.
β¨ disabled( $val ) β¨
again: a value of some sort goes in, and if it's true, out comes ' disabled="disabled"', which you can use in an HTML input π«.
β¨ nl2br( $text ) β¨
give it a string of text where the lines are delimited by newline characters (\n, or possibly \r\n) and it appends an HTML line break (<br />) to every line π. the newline character itself is left completely untouched. hands off. respect the newline.
β¨ text2html( $text ) β¨
give it a string of text with lines delimited by newline characters, possibly with some XML (or (x)HTML) code sprinkled in β it escapes that code with escape_xml() and then appends an HTML line break to every line with nl2br() π₯. two-step combo, ate.
β¨ tagattr( $name, $expr, [$value] ) β¨
bestie, the original page just lists this one with zero description. i'm not gonna make stuff up about it, i'm just here to make sure it's on the list. it's listed. π
β¨ tagattrs( %attrs ) β¨
same situation π β no description on the original page, just the name and the signature. noted, preserved, untouched.
β¨ new_cycle( @items ) β¨
creates a subroutine reference you can use for cycling through the items of the @items array π. so, for example, you can:
my $cycle = new_cycle(qw/red green blue/);
print $cycle->(); # prints 'red'
print $cycle->(); # prints 'green'
print $cycle->(); # prints 'blue'
print $cycle->(); # prints 'red' again
round and round forever, bestie. the cycle never ends and honestly? good for it β¨.
π INTERNAL(?) METHODS π
(yes the question mark is canon, the original page literally wrote it like that π)
β _p( $expression ) β
wraps a Perl expression in a customized wrapper which will be processed by the Tenjin preprocessor and replaced with the standard [== $expression =] π«.
β _P( $expression ) β
wrap a Perl expression in a customized wrapper which will be processed by the Tenjin preprocessor and replaced with the standard [= $expression =] β which means the expression will be escaped β οΈ. that's the difference between _p and _P bestie, one little capital letter, big consequences. iykyk.
β _decode_params( $s ) β
and again, the original page gives this one absolutely nothing to work with π β name and argument only, no description. preserved exactly as-is!
π SEE ALSO π
TenjinTenjin::TemplateTenjin::Context
go read those too, bestie, they're the rest of the friend group π«Ά.
π AUTHOR, LICENSE AND COPYRIGHT π
see Tenjin. short, sweet, and it's giving "the info lives over there" π.
okay that's the whole page!! π
this was Tenjin::Util(3pm) from perl v5.38.2, dated 2024-03-08 β shoutout to the version and the date for showing up, iconic of them β. now go forth and escape your XML, bestie πΈπ¦β¨
π¦ where this page comes from
- debian trixie: libtenjin-perl 1.000001-3 Β· MIT
- ubuntu resolute: libtenjin-perl 1.000001-3 Β· MIT
- ubuntu stonking: libtenjin-perl 1.000001-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms