File Coverage

blib/lib/Locale/TextDomain/OO/Role/DomainAndCategory.pm
Criterion Covered Total %
statement 50 53 94.3
branch 4 8 50.0
condition n/a
subroutine 12 12 100.0
pod 7 7 100.0
total 73 80 91.2


line stmt bran cond sub pod time code
1             package Locale::TextDomain::OO::Role::DomainAndCategory; ## no critic (TidyCode)
2            
3 9     9   9291 use strict;
  9         19  
  9         218  
4 9     9   44 use warnings;
  9         18  
  9         205  
5 9     9   41 use Carp qw(confess cluck);
  9         14  
  9         399  
6 9     9   50 use Locale::TextDomain::OO::Translator;
  9         16  
  9         211  
7 9     9   41 use Moo::Role;
  9         16  
  9         115  
8            
9             our $VERSION = '1.030';
10            
11             requires qw(
12             category
13             domain
14             );
15            
16             our ( @domains, @categories ); ## no critic (PackageVars)
17            
18             sub callback_scope {
19 2     2 1 6 my ( $self, $callback ) = @_;
20            
21 2         6 local @domains = @domains; ## no critic (LocalVars)
22 2         5 local @categories = @categories; ## no critic (LocalVars)
23 2         43 my $domain = $self->domain;
24 2         38 my $category = $self->category;
25 2         13 my $translation = $callback->();
26 2         31 $self->domain($domain);
27 2         93 $self->category($category);
28            
29 2         76 return $translation;
30             }
31            
32             sub begin_d {
33 10     10 1 3218 my ($self, $domain) = @_;
34            
35 10 50       33 defined $domain
36             or confess 'Domain is not defined';
37 10         187 push
38             @domains,
39             $self->domain;
40 10         209 $self->domain($domain);
41            
42 10         383 return $self;
43             }
44            
45             sub begin_c {
46 8     8 1 3192 my ($self, $category) = @_;
47            
48 8 50       27 defined $category
49             or confess 'Category is not defined';
50 8         125 push
51             @categories,
52             $self->category;
53 8         154 $self->category($category);
54            
55 8         282 return $self;
56             }
57            
58             sub begin_dc {
59 4     4 1 3076 my ($self, $domain, $category) = @_;
60            
61 4         17 $self->begin_d($domain);
62 4         14 $self->begin_c($category);
63            
64 4         10 return $self;
65             }
66            
67             sub end_d {
68 8     8 1 16 my $self = shift;
69            
70 8 50       28 if ( ! @domains ) {
71 0         0 cluck 'Tried to get the domain from stack but no domain is not stored';
72 0         0 return $self;
73             }
74 8         177 $self->domain( pop @domains );
75            
76 8         496 return $self;
77             }
78            
79             sub end_c {
80 6     6 1 13 my $self = shift;
81            
82 6 50       21 if ( ! @categories ) {
83 0         0 cluck 'Tried to get the category from stack but no category is stored',
84             return $self;
85             }
86 6         106 $self->category( pop @categories );
87            
88 6         202 return $self;
89             }
90            
91             sub end_dc {
92 4     4 1 9 my $self = shift;
93            
94 4         17 $self->end_d;
95 4         13 $self->end_c;
96            
97 4         9 return $self;
98             }
99            
100             1;
101            
102             __END__