File Coverage

blib/lib/Template/Plugin/Lingua/Conjunction.pm
Criterion Covered Total %
statement 23 38 60.5
branch 2 2 100.0
condition n/a
subroutine 9 14 64.2
pod 2 9 22.2
total 36 63 57.1


line stmt bran cond sub pod time code
1             package Template::Plugin::Lingua::Conjunction;
2              
3 1     1   109399 use 5.006;
  1         5  
  1         58  
4 1     1   7 use strict;
  1         3  
  1         42  
5 1     1   22 use warnings;
  1         2  
  1         43  
6 1     1   7 use base 'Template::Plugin';
  1         2  
  1         913  
7              
8 1     1   1659 use Lingua::Conjunction ();
  1         1091  
  1         215  
9              
10             our $VERSION = '0.02';
11              
12             # This plugin is a singleton with no state at all, so...
13             sub load {
14 1     1 1 18 my($pkg, $context) = @_;
15 1         4 bless \$pkg, $pkg;
16             }
17              
18 3     3 1 5957 sub new { shift }
19              
20             sub conjunction {
21 3     3 0 41 my $me = shift;
22            
23             # Flatten any arrays in the parameters
24 3 100       6 @_ = map { ref $_ ? @$_ : $_ } @_;
  5         16  
25            
26             # And call
27 3         14 goto &Lingua::Conjunction::conjunction;
28             }
29              
30             # Shorter alias
31 2     2 0 69 sub list { goto &conjunction }
32              
33             for(qw(lang separator separator_phrase connector_type penultimate)) {
34 0     0 0   eval qq{
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
35             sub $_ {
36             shift;
37             unshift \@_, 'Lingua::Conjunction';
38             goto &Lingua::Conjunction::$_;
39             }
40             }
41             }
42              
43             1;
44              
45              
46             =head1 NAME
47              
48             Template::Plugin::Lingua::Conjunction - Template Toolkit plugin for human-readable lists
49              
50             =head1 SYNOPSIS
51              
52             [% USE Lingua.Conjunction %]
53             [% Lingua.Conjunction.conjunction("Alice", "Bob", "Charlie") %] have secrets
54             from [% Lingua.Conjunction.list("Eve", "Mallory") %]
55            
56             Alice, Bob, and Charlie have secrets from Eve and Mallory.
57              
58             =head1 DESCRIPTION
59              
60             Lingua::Conjunction is a module to create sentence-style, human-readable lists
61             of items from a Perl list. For example, given the list ("foo", "bar", "baz")
62             it would return the string "foo, bar, and baz". If any of the strings in the
63             list had a comma in them, it would switch to using a semicolon. It supports
64             multiple languages and use of arbitrary separator characters. It handles any
65             number of items gracefully, even two or one.
66              
67             Template::Plugin::Lingua::Conjunction is a wrapper around this module so that
68             it can be used from the Template Toolkit.
69              
70             The main method of this plugin is C (or C for short). It
71             takes a list of items or arrays of items which should be converted and returns
72             a human-readable string representation.
73              
74             Template::Plugin::Lingua::Conjunction also supports Lingua::Conjunction's
75             settings methods, namely C, C, C,
76             C, and C. For documentation on them, see
77             L.
78              
79             =head1 SEE ALSO
80              
81             L, L
82              
83             =head1 AUTHOR
84              
85             Brent Royal-Gordon Ebrentdax@cpan.orgE
86              
87             =head1 COPYRIGHT AND LICENSE
88              
89             Copyright (C) 2006 by Brent Royal-Gordon
90              
91             This library is free software; you can redistribute it and/or modify
92             it under the same terms as Perl itself, either Perl version 5.8.7 or,
93             at your option, any later version of Perl 5 you may have available.
94              
95             =cut