File Coverage

blib/lib/Rose/HTML/Object/Localized.pm
Criterion Covered Total %
statement 37 39 94.8
branch 15 18 83.3
condition 6 12 50.0
subroutine 8 8 100.0
pod 0 2 0.0
total 66 79 83.5


line stmt bran cond sub pod time code
1             package Rose::HTML::Object::Localized;
2              
3 43     43   373 use strict;
  43         85  
  43         1649  
4              
5 43     43   258 use Carp;
  43         107  
  43         3489  
6 43     43   30736 use Rose::HTML::Object::Message::Localizer;
  43         162  
  43         2040  
7              
8 43     43   375 use base 'Rose::Object';
  43         91  
  43         7719  
9              
10             our $VERSION = '0.600';
11              
12             #our $Debug = 0;
13              
14             use Rose::HTML::Object::MakeMethods::Localization
15             (
16 43         613 localized_errors =>
17             [
18             'errors',
19             ],
20 43     43   27611 );
  43         190  
21              
22             use Rose::Class::MakeMethods::Generic
23             (
24 43         313 inheritable_scalar =>
25             [
26             'default_localizer',
27             'default_locale',
28             ],
29 43     43   8682 );
  43         91  
30              
31             sub localizer
32             {
33 230     230 0 160415 my($invocant) = shift;
34              
35             # Called as object method
36 230 100       604 if(my $class = ref $invocant)
37             {
38 209 50       475 if(@_)
39             {
40 0         0 return $invocant->{'localizer'} = shift;
41             }
42              
43 209   33     1189 return $invocant->{'localizer'} || $class->default_localizer;
44             }
45             else # Called as class method
46             {
47 21 100       72 if(@_)
48             {
49 2         15 return $invocant->default_localizer(@_);
50             }
51              
52 19         87 return $invocant->default_localizer
53             }
54             }
55              
56             sub locale
57             {
58 94     94 0 647 my($invocant) = shift;
59              
60             # Called as an object method
61 94 100       246 if(my $class = ref $invocant)
62             {
63 93 100       228 if(@_)
64             {
65 15         50 return $invocant->{'locale'} = shift;
66             }
67              
68 78 100       274 return $invocant->{'locale'} if($invocant->{'locale'});
69              
70 47         106 foreach my $parent_name (qw(parent_group parent_field parent_form parent))
71             {
72 184 100 100     1244 if($invocant->can($parent_name) && (my $parent = $invocant->$parent_name()))
73             {
74 4         39 my $locale = $parent->locale;
75 4 50       128 return $locale if(defined $locale);
76             }
77             }
78              
79 43   33     103 return $invocant->localizer->locale || $invocant->localizer->default_locale;
80             }
81             else # Called as a class method
82             {
83 1 50       4 if(@_)
84             {
85 0         0 return $invocant->default_locale(shift);
86             }
87              
88 1   33     3 return $invocant->localizer->locale || $invocant->default_locale;
89             }
90             }
91              
92             1;