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   11627 use strict;
  9         27  
  9         272  
4 9     9   51 use warnings;
  9         24  
  9         265  
5 9     9   52 use Carp qw(confess cluck);
  9         19  
  9         524  
6 9     9   62 use Locale::TextDomain::OO::Translator;
  9         40  
  9         294  
7 9     9   60 use Moo::Role;
  9         21  
  9         150  
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         8 local @domains = @domains; ## no critic (LocalVars)
22 2         7 local @categories = @categories; ## no critic (LocalVars)
23 2         54 my $domain = $self->domain;
24 2         50 my $category = $self->category;
25 2         18 my $translation = $callback->();
26 2         87 $self->domain($domain);
27 2         125 $self->category($category);
28            
29 2         110 return $translation;
30             }
31            
32             sub begin_d {
33 10     10 1 4029 my ($self, $domain) = @_;
34            
35 10 50       39 defined $domain
36             or confess 'Domain is not defined';
37 10         237 push
38             @domains,
39             $self->domain;
40 10         242 $self->domain($domain);
41            
42 10         460 return $self;
43             }
44            
45             sub begin_c {
46 8     8 1 3923 my ($self, $category) = @_;
47            
48 8 50       32 defined $category
49             or confess 'Category is not defined';
50 8         156 push
51             @categories,
52             $self->category;
53 8         191 $self->category($category);
54            
55 8         366 return $self;
56             }
57            
58             sub begin_dc {
59 4     4 1 3971 my ($self, $domain, $category) = @_;
60            
61 4         22 $self->begin_d($domain);
62 4         17 $self->begin_c($category);
63            
64 4         13 return $self;
65             }
66            
67             sub end_d {
68 8     8 1 19 my $self = shift;
69            
70 8 50       33 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         245 $self->domain( pop @domains );
75            
76 8         650 return $self;
77             }
78            
79             sub end_c {
80 6     6 1 16 my $self = shift;
81            
82 6 50       31 if ( ! @categories ) {
83 0         0 cluck 'Tried to get the category from stack but no category is stored',
84             return $self;
85             }
86 6         132 $self->category( pop @categories );
87            
88 6         249 return $self;
89             }
90            
91             sub end_dc {
92 4     4 1 14 my $self = shift;
93            
94 4         21 $self->end_d;
95 4         16 $self->end_c;
96            
97 4         12 return $self;
98             }
99            
100             1;
101            
102             __END__