Tenjin::Util(3pm)

πŸ“¦
version 1.000001 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸŽ€ 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 &lt;h1&gt;You &amp; Me&lt;/h1&gt;<br />\n&lt;h2&gt;Me &amp; You&lt;/h2&gt;

πŸ’œ 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 🌈

  • Tenjin
  • Tenjin::Template
  • Tenjin::Context

go read those too, bestie, they're the rest of the friend group 🫢.


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