Templa...Inflect(3pm)

πŸ“¦
version 0.04 Β· 2 versions
  • 0.04 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.04 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Template::Plugin::Lingua::EN::Inflect β€” the interface to the Lingua::EN::Inflect module, bestie πŸ’–

okay so real quick, the page you're reading is Templa...Inflect(3pm) from the User Contributed Perl Documentation, and it's literally your group chat with English grammar. she does plurals. she does "a" vs "an". she turns numbers into words. she's THAT girl πŸ’…


🌸 SYNOPSIS 🌸

  [% USE infl = Lingua.EN.Inflect; -%]
  [% FILTER inflect(number => 42); -%]
    There PL_V(was) NO(error).
    PL_ADJ(This) PL_N(error) PL_V(was) fatal.
  [% END; -%]

  [% "... and "; infl.ORD(9); "ly..." %]

and here's what actually comes out, no cap:

#   There were 42 errors.
#   These errors were fatal.
#   ... and 9thly...

πŸ¦‹ DESCRIPTION πŸ¦‹

So Lingua::EN::Inflect is an interface to Damian Conway's Linua::EN::Inflect Perl module β€” yes, that's exactly how it's spelled in here, I'm not touching it 😭 β€” and that module is the one doing all the heavy lifting: plural inflections, picking "a" or "an" for English words, and full-on manipulation of numbers as words.

The plugin hands you an inflect filter, and you use it to interpolate inflections right inside a string. The NUM() function sets a persistent default value that gets used any time an optional number argument is left out. And if you wanna set the number for just one specific call to inflect, you can do that with a number option instead. slay, choices πŸ’…

for the full gory details of the inflection functionality, go read the Lingua::EN::Inflect manual. this page is not gonna spoil it for you.

πŸ‘‘ OBJECT METHODS πŸ‘‘

  • infl.A($string, $opt_number) β€” prepends the correct indefinite article to a word, based on how it's pronounced. If the second argument is supplied, and its value is numeric and not 1, then the value of that second argument gets used instead. e.g. infl.A("idea") returns an idea ✨
  • AN($string, $opt_arg) β€” synonym for A(). same energy, different spelling πŸ’–
  • NO($string, $opt_arg) β€” you give it a word and an optional count, and it gives you back the count followed by the correctly inflected word. iconic.
  • NUM($string, $opt_arg) β€” sets a persistent default number value, which then gets used whenever the optional second number argument is omitted. You can take that default back off by calling NUM() with no arguments at all. Normally NUM() returns its first argument β€” BUT, if you call NUM() with a second argument that is defined and evaluates to false, then NUM() returns an empty string instead. plot twist.
  • NUMWORDS($string, $opt_arg) β€” takes a number (cardinal or ordinal) and returns an English representation of it. In scalar context you get a string back. In list context, each comma-separated chunk comes back as its own separate element. multi-purpose queen 🫢
  • ORD($number) β€” takes one single argument and forms its ordinal equivalent. If the argument isn't a numerical integer, it just slaps -th on the end. no thoughts, just -th πŸ’€
  • PART_PRES($string, $opt_arg) β€” returns the present participle for a third person singular verb.
    PART_PRES("runs");          # returns "running"
  • PL($string, $opt_arg) β€” returns the plural of a singular English noun, pronoun, verb or adjective. the whole buffet 🌈
  • PL_N($string, $opt_arg) β€” returns the plural of a singular English noun or pronoun.
  • PL_V($string, $opt_arg) β€” returns the plural conjugation of the singular form of a conjugated verb.
  • PL_ADJ($string, $opt_arg) β€” returns the plural form of a singular form of certain types of adjectives.
  • PL_eq($string, $opt_arg)
  • PL_N_eq($string, $opt_arg)
  • PL_V_eq($string, $opt_arg)
  • PL_ADJ_eq($string, $opt_arg)
  • classical($string, $opt_arg)
  • def_noun($string, $opt_arg)
  • def_verb($string, $opt_arg)
  • def_adj($string, $opt_arg)
  • def_a($string, $opt_arg)
  • def_an($string, $opt_arg)
bestie I am telling you exactly what the page tells me and nothing more β€” those last ones are listed with their signatures and no descriptions. that's the whole tea β˜• (also the TODO below is literally asking for them to get documented, so, yeah πŸ’€)

🧚 INTERNAL METHODS 🧚

  • tt_inflect($string, $opt_arg) β€” the underlying inflect filter. the machinery behind the curtain, lowkey the main character πŸŽ€

πŸ”₯ TODO πŸ”₯

  • Finish off documenting the object methods.
  • Provide tests for all methods in the test suite.
  • It would also be nice to have methods that spelled out numbers that were less than a certain threshold and that formatted large numbers with commas, for example:
     inflect("There PL_V(was) NO(error).", number => 0);
     # outputs: "There were no errors."

     inflect("There PL_V(was) NO(error).", number => 1);
     # outputs: "There was one errors."

     inflect("There PL_V(was) NO(error).", number => 3);
     # outputs: "There were three errors."

     inflect("There PL_V(was) NO(error).", number => 1042);
     # outputs: "There were 1,042 errors."

and this would require changes to the Lingua::EN::Inflect module. so, you know. someday ✨


⭐ SEE ALSO ⭐

Lingua::EN::Inflect, Template, "Template::Plugin"


πŸ•ŠοΈ DEDICATION πŸ•ŠοΈ

This distribution was originally created by Andrew Ford. Sadly in early 2014, Andrew was diagnosed with Pancreatic Cancer and passed away peacfully at home on 25th April 2014.

One of his wishes was for his OpenSource work to continue. At his funeral, many of his colleagues and friends, spoke of how he felt like a person of the world, and how he embrace the idea of OpenSource being for the benefit of the world.

Anyone wishing to donate in memory of Andrew, please consider the following charities:


πŸ’œ AUTHOR πŸ’œ

  Original Author:    Andrew Ford               2005-2014
  Current Maintainer: Barbie <barbie@cpan.org>  2014

🌟 ACKNOWLEDGEMENTS 🌟

Andrew Ford wrote the original plugin code (basing it heavily on the Template::Plugin::Autoformat code).

Damian Conway <damian@conway.org> wrote the Lingua::EN::Inflect module, which does all the clever stuff. and honestly? the clever stuff is very clever πŸ’…


Copyright (C) 2005-2014 Andrew Ford Copyright (C) 2014-2015 Barbie for Miss Barbell Productions.

This distribution is free software; you can redistribute it and/or modify it under the Artistic Licence v2.


and that's the whole page bestie!! 🫢 this one's perl v5.34.0, dated 2022-06-17 β€” mwah, go inflect something iconic βœ¨πŸ’–