Template-Plugin-Lingua-EN-Inflect-0.04/0000755000175000017500000000000012451463270017001 5ustar barbiebarbieTemplate-Plugin-Lingua-EN-Inflect-0.04/Changes0000644000175000017500000000114712451463156020302 0ustar barbiebarbieRevision history for Template-Plugin-Lingua-EN-Inflect ====================================================== 0.04 2015-01-02 - fixed license fields in META.json to be lists. - extended functional test suite. 0.03 2014-06-23 - new maintainer: BARBIE. - change file dates changed to meet W3CDTF standards. - added LICENSE file. - updated META.yml, added META.json. - reworked Makefile.PL for clarity. - extended test suite. 0.02 2005-10-21T08:04:19Z - expanded documentation a bit 0.01 2005-09-01T15:38:02Z - original version Template-Plugin-Lingua-EN-Inflect-0.04/README0000644000175000017500000000353712451266134017671 0ustar barbiebarbieTemplate-Plugin-Lingua-EN-Inflect ================================= The Lingua::EN::Inflect is an interface to Damian Conway's Linua::EN::Inflect Perl module, which provides plural inflections, "a"/"an" selection for English words, and manipulation of numbers as words. The plugin provides an 'inflect' filter, which can be used to interpolate inflections in a string. The NUM() function sets a persistent default value to be used whenever an optional number argument is omitted. The number to be used for a particular invocation of 'inflect' can also be specified with a 'number' option. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these modules: Template Template::Plugin Lingua-EN-Inflect For testing the module requires these modules: IO::File Test::More For optional testing the module would like these modules: Test::CPAN::Meta Test::CPAN::Meta::JSON Test::Pod Test::Pod::Coverage 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: * Dignity in Dying - http://www.dignityindying.org.uk/ * Marie Curie Cancer Care - http://www.mariecurie.org.uk/ COPYRIGHT AND LICENSE 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. Template-Plugin-Lingua-EN-Inflect-0.04/t/0000755000175000017500000000000012451463270017244 5ustar barbiebarbieTemplate-Plugin-Lingua-EN-Inflect-0.04/t/00use.t0000644000175000017500000000016512350756745020401 0ustar barbiebarbie#!/usr/bin/perl -w use strict; use Test::More tests => 1; BEGIN { use_ok 'Template::Plugin::Lingua::EN::Inflect' } Template-Plugin-Lingua-EN-Inflect-0.04/t/96metatest.t0000644000175000017500000000202012350665370021433 0ustar barbiebarbie#!/usr/bin/perl -w use strict; use Test::More; # Skip if doing a regular install plan skip_all => "Author tests not required for installation" unless ( $ENV{AUTOMATED_TESTING} ); eval "use Test::CPAN::Meta::JSON"; plan skip_all => "Test::CPAN::Meta::JSON required for testing META.json files" if $@; plan 'no_plan'; my $meta = meta_spec_ok(undef,undef,@_); use Template::Plugin::Lingua::EN::Inflect; my $version = $Template::Plugin::Lingua::EN::Inflect::VERSION; is($meta->{version},$version, 'META.json distribution version matches'); if($meta->{provides}) { for my $mod (keys %{$meta->{provides}}) { is($meta->{provides}{$mod}{version},$version, "META.json entry [$mod] version matches distribution version"); eval "require $mod"; my $VERSION = '$' . $mod . '::VERSION'; my $v = eval "$VERSION"; is($meta->{provides}{$mod}{version},$v, "META.json entry [$mod] version matches module version"); isnt($meta->{provides}{$mod}{version},0); } } Template-Plugin-Lingua-EN-Inflect-0.04/t/01inflect.t0000644000175000017500000000351112350756745021230 0ustar barbiebarbie#!/usr/bin/perl -w use strict; use Template::Test; test_expect(\*DATA); __END__ --test-- [%- # testing inflect filter with a block USE Lingua.EN.Inflect; FILTER inflect(number => 42); -%] There PL_V(was) NO(error). PL_ADJ(This) PL_N(error) PL_V(was) fatal. [% END; -%] --expect-- There were 42 errors. These errors were fatal. --test-- [% USE Lingua.EN.Inflect -%] [% "NUM(3) PL_N(error)." | inflect -%] --expect-- 3 errors. --test-- [% USE i = Lingua.EN.Inflect -%] [% "NUM(0,0)There PL_V(was) NO(error)." | inflect -%] --expect-- There were no errors. --test-- [%- # testing inflect USE inflect = Lingua.EN.Inflect; "NUM(0,0)There PL_V(was) NO(error)." | inflect; -%] --expect-- There were no errors. --test-- [% # testing inflect USE Lingua.EN.Inflect; "NUM(1,0)There PL_V(was) NO(error)." | inflect; -%] --expect-- There was 1 error. --test-- [%- # testing inflect USE Lingua.EN.Inflect; "NUM(3,0)There PL_V(was) NO(error)." | inflect; -%] --expect-- There were 3 errors. --test-- [%- # testing inflect USE Lingua.EN.Inflect; "There PL_V(was) NO(error)." | inflect(number => 5); -%] --expect-- There were 5 errors. --test-- [% # testing NO() USE i = Lingua.EN.Inflect; FOREACH n IN [ 0, 1, 2, 3, 42 ]; i.NO('cat', n); ', ' UNLESS loop.last; END; -%] --expect-- no cats, 1 cat, 2 cats, 3 cats, 42 cats --test-- [% # testing NUMWORDS() for 1, 2, 3, ... USE i = Lingua.EN.Inflect; FOREACH n IN [ 1, 2, 3, 4, 42, 1000 ]; i.NUMWORDS(n); ', ' UNLESS loop.last; END; -%] --expect-- one, two, three, four, forty-two, one thousand --test-- [% # testing ORD() USE Lingua.EN.Inflect; FOREACH n IN [ 1, 2, 3, 4, 5, 100 ]; Lingua.EN.Inflect.ORD(n); ', ' UNLESS loop.last; END; -%] --expect-- 1st, 2nd, 3rd, 4th, 5th, 100th Template-Plugin-Lingua-EN-Inflect-0.04/t/95changedate.t0000644000175000017500000000241312350665370021675 0ustar barbiebarbie#!/usr/bin/perl -w use strict; use Test::More; use IO::File; # Skip if doing a regular install plan skip_all => "Author tests not required for installation" unless ( $ENV{AUTOMATED_TESTING} ); my $fh = IO::File->new('Changes','r') or plan skip_all => "Cannot open Changes file"; plan 'no_plan'; use Template::Plugin::Lingua::EN::Inflect; my $version = $Template::Plugin::Lingua::EN::Inflect::VERSION; my $latest = 0; while(<$fh>) { next unless(m!^\d!); $latest = 1 if(m!^$version!); # 2012-08-26T01:02 or 2012-08-26T01:02:03 or 2012-08-26T01:02:03.04 or 2012-08-26T01:02+01:00 like($_, qr! \d[\d._]+\s+ # version ( \d{4}-\d{2}-\d{2} # 2012-08-26 - YYYY-MM-DD ( T\d{2}:\d{2} # T01:02 - Thh:mm ( :\d{2} # :02 - :ss ( \.\d+ # .2 - .ss (microseconds) )? )? ( (Z|[-+]\d+:\d+) # +01:00 - timezone )? )? ) !x,'... version has a date'); } is($latest,1,'... latest version not listed'); Template-Plugin-Lingua-EN-Inflect-0.04/t/91podcover.t0000644000175000017500000000054612350664035021431 0ustar barbiebarbie#!/usr/bin/perl -w use strict; use Test::More; # Skip if doing a regular install plan skip_all => "Author tests not required for installation" unless ( $ENV{AUTOMATED_TESTING} ); eval "use Test::Pod::Coverage 0.08"; plan skip_all => "Test::Pod::Coverage 0.08 required for testing POD coverage" if $@; all_pod_coverage_ok({ also_private => ['new'] }); Template-Plugin-Lingua-EN-Inflect-0.04/t/02inflect.t0000644000175000017500000000451212451462355021224 0ustar barbiebarbie#!/usr/bin/perl -w use strict; use Template::Plugin::Lingua::EN::Inflect; use Test::More tests => 43; my $class = 'Template::Plugin::Lingua::EN::Inflect'; is($class->classical(1),undef); $class->inflect( number => 2 ); is($class->NO('formulas'),'no formulas'); is($class->NO('formulae'),'no formulae'); is($class->PL_N('formula'),'formulae'); # classical 'ancient' active $class->def_noun( "kin" => "kine" ); ok ( $class->NO("kin",0) eq "no kin", "kin -> kine (user defined)..." ); ok ( $class->NO("kin",1) eq "1 kin" ); ok ( $class->NO("kin",2) eq "2 kine" ); $class->def_adj( 'red' => 'red|gules' ); ok ( $class->PL("red",0) eq "red" , "red -> gules..."); ok ( $class->PL("red",1) eq "red" ); ok ( $class->PL("red",2) eq "gules" ); $class->def_verb( 'foobar' => 'feebar', 'foobar' => 'feebar', 'foobars' => 'feebar' ); ok ( $class->PL("foobar",2) eq "feebar", "foobar -> feebar (user defined)..." ); ok ( $class->PL("foobars",2) eq "feebar" ); ok ( $class->A('ant') eq "an ant" ); ok ( $class->A('bat') eq "a bat" ); ok ( $class->ORD(1) eq "1st" ); ok ( $class->ORD('one') eq "first" ); ok ( $class->PART_PRES("bats") eq "batting" ); is($class->NUMWORDS('21'),'twenty-one'); is($class->NUMWORDS('21',group => 1),'two, one'); is($class->PL_V('is',2),'are'); is($class->PL_ADJ('my',2),'our'); is($class->PL_eq("index","indices"),'s:p'); is($class->PL_N_eq('kin','kine'),'s:p'); is($class->PL_N_eq('kin','kin'),'eq'); is($class->PL_V_eq('is','are'),'s:p'); is($class->PL_V_eq('is','is'),'eq'); is($class->PL_ADJ_eq('my','our'),'s:p'); is($class->PL_ADJ_eq('my','yours'),''); # invalid is($class->A('formula',1),'a formula'); is($class->AN('formula',1),'a formula'); is($class->A('alien',1),'an alien'); is($class->AN('alien',1),'an alien'); is($class->NUM(2),2); is($class->PL_V('is'),'are'); is($class->PL_ADJ('my'),'our'); is($class->NUM(),''); is($class->classical(0),undef); is($class->NO('formulas'),'no formula'); is($class->NO('formulae'),'no formulaes'); is($class->PL_N('formula'),'formulas'); # classical 'ancient' not active ok ( $class->PL("red",0) eq "red", "red -> red..." ); ok ( $class->PL("red",1) eq "red" ); ok ( $class->PL("red",2) eq "red" ); #is($class->def_a { shift; return Lingua::EN::Inflect::def_a(@_); } #is($class->def_an { shift; return Lingua::EN::Inflect::def_an(@_); } Template-Plugin-Lingua-EN-Inflect-0.04/t/94metatest.t0000644000175000017500000000177212451266134021443 0ustar barbiebarbie#!/usr/bin/perl -w use strict; use Test::More; # Skip if doing a regular install plan skip_all => "Author tests not required for installation" unless ( $ENV{AUTOMATED_TESTING} ); eval "use Test::CPAN::Meta"; plan skip_all => "Test::CPAN::Meta required for testing META.yml" if $@; plan 'no_plan'; my $meta = meta_spec_ok(undef,undef,@_); use Template::Plugin::Lingua::EN::Inflect; my $version = $Template::Plugin::Lingua::EN::Inflect::VERSION; is($meta->{version},$version, 'META.yml distribution version matches'); if($meta->{provides}) { for my $mod (keys %{$meta->{provides}}) { is($meta->{provides}{$mod}{version},$version, "META.yml entry [$mod] version matches distribution version"); eval "require $mod"; my $VERSION = '$' . $mod . '::VERSION'; my $v = eval "$VERSION"; is($meta->{provides}{$mod}{version},$v, "META.yml entry [$mod] version matches module version"); isnt($meta->{provides}{$mod}{version},0); } } Template-Plugin-Lingua-EN-Inflect-0.04/t/90podtest.t0000644000175000017500000000045312350664035021266 0ustar barbiebarbie#!/usr/bin/perl -w use strict; use Test::More; # Skip if doing a regular install plan skip_all => "Author tests not required for installation" unless ( $ENV{AUTOMATED_TESTING} ); eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Template-Plugin-Lingua-EN-Inflect-0.04/lib/0000755000175000017500000000000012451463270017547 5ustar barbiebarbieTemplate-Plugin-Lingua-EN-Inflect-0.04/lib/Template/0000755000175000017500000000000012451463270021322 5ustar barbiebarbieTemplate-Plugin-Lingua-EN-Inflect-0.04/lib/Template/Plugin/0000755000175000017500000000000012451463270022560 5ustar barbiebarbieTemplate-Plugin-Lingua-EN-Inflect-0.04/lib/Template/Plugin/Lingua/0000755000175000017500000000000012451463270023777 5ustar barbiebarbieTemplate-Plugin-Lingua-EN-Inflect-0.04/lib/Template/Plugin/Lingua/EN/0000755000175000017500000000000012451463270024301 5ustar barbiebarbieTemplate-Plugin-Lingua-EN-Inflect-0.04/lib/Template/Plugin/Lingua/EN/Inflect.pm0000644000175000017500000002104012451271150026212 0ustar barbiebarbiepackage Template::Plugin::Lingua::EN::Inflect; use strict; use warnings; use vars qw($VERSION); $VERSION = 0.04; require Template::Plugin; use base qw(Template::Plugin); use Lingua::EN::Inflect qw( inflect ); sub new { my ($class, $context, $options) = @_; my $filter_factory; my $plugin; if ($options) { # create a closure to generate filters with additional options $filter_factory = sub { my $context = shift; my $filtopt = ref $_[-1] eq 'HASH' ? pop : {}; @$filtopt{ keys %$options } = values %$options; return sub { tt_inflect(@_, $filtopt); }; }; # and a closure to represent the plugin $plugin = sub { my $plugopt = ref $_[-1] eq 'HASH' ? pop : {}; @$plugopt{ keys %$options } = values %$options; tt_inflect(@_, $plugopt); }; } else { # simple filter factory closure (no legacy options from constructor) $filter_factory = sub { my $context = shift; my $filtopt = ref $_[-1] eq 'HASH' ? pop : {}; return sub { tt_inflect(@_, $filtopt); }; }; # plugin without options can be static $plugin = \&tt_inflect; } # now define the filter and return the plugin $context->define_filter('inflect', [ $filter_factory => 1 ]); return bless $plugin, $class; } sub tt_inflect { my $options = ref $_[-1] eq 'HASH' ? pop : {}; my $number = $options->{ number }; Lingua::EN::Inflect::NUM($number) if $number; my $out = inflect(join('', @_)); return $out; } sub classical { shift; return Lingua::EN::Inflect::classical(@_); } sub def_noun { shift; return Lingua::EN::Inflect::def_noun(@_); } sub def_verb { shift; return Lingua::EN::Inflect::def_verb(@_); } sub def_adj { shift; return Lingua::EN::Inflect::def_adj(@_); } sub def_a { shift; return Lingua::EN::Inflect::def_a(@_); } sub def_an { shift; return Lingua::EN::Inflect::def_an(@_); } sub A { shift; return Lingua::EN::Inflect::A(@_); } sub AN { shift; return Lingua::EN::Inflect::AN(@_); } sub NO { shift; return Lingua::EN::Inflect::NO(@_); } sub NUM { shift; return Lingua::EN::Inflect::NUM(@_); } sub NUMWORDS { shift; return Lingua::EN::Inflect::NUMWORDS(@_); } sub ORD { return Lingua::EN::Inflect::ORD($_[1]); } sub PART_PRES { shift; return Lingua::EN::Inflect::PART_PRES(@_); } sub PL { shift; return Lingua::EN::Inflect::PL(@_); } sub PL_N { shift; return Lingua::EN::Inflect::PL_N(@_); } sub PL_V { shift; return Lingua::EN::Inflect::PL_V(@_); } sub PL_ADJ { shift; return Lingua::EN::Inflect::PL_ADJ(@_); } sub PL_eq { shift; return Lingua::EN::Inflect::PL_eq(@_); } sub PL_N_eq { shift; return Lingua::EN::Inflect::PL_N_eq(@_); } sub PL_V_eq { shift; return Lingua::EN::Inflect::PL_V_eq(@_); } sub PL_ADJ_eq { shift; return Lingua::EN::Inflect::PL_ADJ_eq(@_); } 1; __END__ =head1 NAME Template::Plugin::Lingua::EN::Inflect - Interface to Lingua::EN::Inflect module =head1 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..." %] # Output: # There were 42 errors. # These errors were fatal. # ... and 9thly... =head1 DESCRIPTION The Lingua::EN::Inflect is an interface to Damian Conway's Linua::EN::Inflect Perl module, which provides plural inflections, "a"/"an" selection for English words, and manipulation of numbers as words. The plugin provides an 'inflect' filter, which can be used to interpolate inflections in a string. The NUM() function sets a persistent default value to be used whenever an optional number argument is omitted. The number to be used for a particular invocation of 'inflect' can also be specified with a 'number' option. For the full gory details of the inflection functionality refer to the L manual. =head1 OBJECT METHODS =over 4 =item C prepends the appropriate indefinite article to a word, depending on its pronunciation. If the second argument is provided and its value is numeric and not 1 then the value of the second argument is used instead. e.g. C returns C<"an idea"> =item C synonym for C =item C given a word and an optional count, returns the count followed by the correctly inflected word =item C sets a persistent I value, which is subsequently used whenever an optional second I argument is omitted. The default value thus set can subsequently be removed by calling C with no arguments. C normally returns its first argument, however if C is called with a second argument that is defined and evaluates to false then C returns an empty string. =item C takes a number (cardinal or ordinal) and returns an English represen- tation of that number. In a scalar context a string is returned. In a list context each comma-separated chunk is returned as a separate element. =item C takes a single argument and forms its ordinal equivalent. If the argument isn't a numerical integer, it just adds "-th". =item C returns the present participle for a third person singluar verb PART_PRES("runs"); # returns "running" =item C returns the plural of a I English noun, pronoun, verb or adjective. =item C returns the plural of a I English noun or pronoun. =item C returns the plural conjugation of the I form of a conjugated verb. =item C returns the plural form of a I form of certain types of adjectives. =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =back =head1 INTERNAL METHODS =over 4 =item C The underlying inflect filter. =back =head1 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." This would require changes to the L module. =head1 SEE ALSO L, L