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   416 use strict;
  43         96  
  43         1298  
4              
5 43     43   245 use Carp;
  43         96  
  43         2481  
6 43     43   29231 use Rose::HTML::Object::Message::Localizer;
  43         135  
  43         1464  
7              
8 43     43   295 use base 'Rose::Object';
  43         100  
  43         5328  
9              
10             our $VERSION = '0.600';
11              
12             #our $Debug = 0;
13              
14             use Rose::HTML::Object::MakeMethods::Localization
15             (
16 43         399 localized_errors =>
17             [
18             'errors',
19             ],
20 43     43   22036 );
  43         145  
21              
22             use Rose::Class::MakeMethods::Generic
23             (
24 43         233 inheritable_scalar =>
25             [
26             'default_localizer',
27             'default_locale',
28             ],
29 43     43   7458 );
  43         103  
30              
31             sub localizer
32             {
33 230     230 0 6064 my($invocant) = shift;
34              
35             # Called as object method
36 230 100       557 if(my $class = ref $invocant)
37             {
38 209 50       433 if(@_)
39             {
40 0         0 return $invocant->{'localizer'} = shift;
41             }
42              
43 209   33     877 return $invocant->{'localizer'} || $class->default_localizer;
44             }
45             else # Called as class method
46             {
47 21 100       62 if(@_)
48             {
49 2         11 return $invocant->default_localizer(@_);
50             }
51              
52 19         75 return $invocant->default_localizer
53             }
54             }
55              
56             sub locale
57             {
58 94     94 0 716 my($invocant) = shift;
59              
60             # Called as an object method
61 94 100       227 if(my $class = ref $invocant)
62             {
63 93 100       213 if(@_)
64             {
65 15         51 return $invocant->{'locale'} = shift;
66             }
67              
68 78 100       297 return $invocant->{'locale'} if($invocant->{'locale'});
69              
70 47         96 foreach my $parent_name (qw(parent_group parent_field parent_form parent))
71             {
72 184 100 100     1307 if($invocant->can($parent_name) && (my $parent = $invocant->$parent_name()))
73             {
74 4         16 my $locale = $parent->locale;
75 4 50       115 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       5 if(@_)
84             {
85 0         0 return $invocant->default_locale(shift);
86             }
87              
88 1   33     4 return $invocant->localizer->locale || $invocant->default_locale;
89             }
90             }
91              
92             1;