blib/lib/UR/Vocabulary.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 91 SCAR 40.3
CC
7
Cov
0%
convert_to_title_case
12.0
convert_to_special_case
12.0
_words_with_special_case_hashref
6.0
CRAP 56.0
1  
2 package UR::Vocabulary;
3  
4 use strict;
5 use warnings;
6 use Lingua::EN::Inflect ("PL_V","PL");
7  
8 require UR;
9 our $VERSION = "0.46"; # UR $VERSION;
10  
11 UR::Object::Type->define(
12 class_name => 'UR::Vocabulary',
13 is => ['UR::Singleton'],
14 doc => 'A word in the vocabulary of a given namespace.',
15 );
16  
17 sub get_words_with_special_case {
18 shift->_singleton_class_name->_words_with_special_case;
19 }
20  
21 sub _words_with_special_case {
22 return ('UR');
23 }
24  
25 sub convert_to_title_case {
26 my $conversion_hashref = shift->_words_with_special_case_hashref;
27 my @results;
28 for my $word_in(@_) {
29 my $word = lc($word_in);
30 if (my $uc = $conversion_hashref->{$word}) {
31 push @results, $uc;
32 }
33 else {
34 push @results, ucfirst($word);
35 }
36 }
37 return $results[0] if @results == 1 and !wantarray;
38 return @results;
39 }
40  
41 sub convert_to_special_case {
42 my $conversion_hashref = shift->_words_with_special_case_hashref;
43 my @results;
44 for my $word_in(@_) {
45 my $word = lc($word_in);
46 if (my $sc = $conversion_hashref->{$word}) {
47 push @results, $sc;
48 }
49 else {
50 push @results, $word_in;
51 }
52 }
53 return $results[0] if @results == 1 and !wantarray;
54 return @results;
55 }
56  
57  
58 sub _words_with_special_case_hashref {
59 my $self = shift->_singleton_object;
60 my $hashref = $self->{_words_with_special_case_hashref};
61 return $hashref if $hashref;
62 $hashref = { map { lc($_) => $_ } $self->get_words_with_special_case };
63 $self->{_words_with_special_case_hashref} = $hashref;
64 return $hashref;
65 }
66  
67 sub singular_to_plural {
68 my $self = shift;
69 return map { PL($_) } @_;
70 }
71  
72 our %exceptions =
73 (
74 statuses => 'status',
75 is => 'is',
76 has => 'has',
77 cds => 'cds',
78 );
79  
80 sub plural_to_singular {
81 my $self = shift;
82 my ($lc,$override);
83 return map {
84 $lc = lc($_);
85 $override = $exceptions{$lc};
86 ( $override ? $override : PL_V($_) )
87 } @_;
88 }
89  
90  
91  
92  
93  
94 1;