File Coverage

blib/lib/Locale/XGettext/Util/Flag.pm
Criterion Covered Total %
statement 34 40 85.0
branch 16 28 57.1
condition 2 3 66.6
subroutine 8 10 80.0
pod 8 8 100.0
total 68 89 76.4


line stmt bran cond sub pod time code
1             #! /bin/false
2              
3             # Copyright (C) 2016-2017 Guido Flohr ,
4             # all rights reserved.
5              
6             # This program is free software; you can redistribute it and/or modify it
7             # under the terms of the GNU Library General Public License as published
8             # by the Free Software Foundation; either version 2, or (at your option)
9             # any later version.
10              
11             # This program is distributed in the hope that it will be useful,
12             # but WITHOUT ANY WARRANTY; without even the implied warranty of
13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14             # Library General Public License for more details.
15              
16             # You should have received a copy of the GNU Library General Public
17             # License along with this program; if not, write to the Free Software
18             # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19             # USA.
20              
21             package Locale::XGettext::Util::Flag;
22             $Locale::XGettext::Util::Flag::VERSION = '0.7';
23 15     15   105 use strict;
  15         39  
  15         506  
24              
25 15     15   111 use Locale::TextDomain qw(Locale-XGettext);
  15         33  
  15         95  
26              
27             sub new {
28 10     10 1 37 my ($class, %args) = @_;
29              
30 10 50       48 return if !defined $args{function};
31 10 50       19 return if !defined $args{flag};
32 10 50       35 return if !defined $args{arg};
33 10 50       19 return if !length $args{function};
34 10 50       25 return if !length $args{flag};
35             # That would break the output.
36 10 50       32 return if $args{flag} =~ /\n/;
37 10 50       37 return if $args{arg} !~ /^[1-9][0-9]*$/;
38              
39 10 50 66     34 if (!$args{pass} && !$args{arg}) {
40 0 0       0 $args{pass} = 1 if $args{flag} =~ s/^pass-//;
41 0 0       0 $args{no} = 1 if $args{flag} =~ s/^no-//;
42             }
43              
44 10         27 my %seen;
45             my $comment;
46 10         0 my $comment_seen;
47 10         0 my $context_seen;
48             my $self = {
49             function => $args{function},
50             arg => $args{arg},
51             flag => $args{flag}
52 10         39 };
53              
54 10 100       22 $self->{pass} = 1 if $args{pass};
55 10 100       22 $self->{no} = 1 if $args{no};
56              
57 10         44 bless $self, $class;
58             }
59              
60             sub newFromString {
61 10     10 1 20 my ($class, $orig_spec) = @_;
62            
63 10         17 my $spec = $orig_spec;
64 10         20 $spec =~ s/\s+//g;
65              
66 10         34 my ($function, $arg, $flag) = split /:/, $spec, 3;
67            
68 10         19 my ($pass, $no);
69 10 100       26 $pass = 1 if $flag =~ s/^pass-//;
70 10 100       25 $no = 1 if $flag =~ s/^no-//;
71              
72 10         23 return $class->new(
73             function => $function,
74             arg => $arg,
75             flag => $flag,
76             no => $no,
77             pass => $pass,
78             );
79             }
80              
81             sub function {
82 19     19 1 48 shift->{function};
83             }
84              
85             sub arg {
86 20     20 1 68 shift->{arg};
87             }
88              
89             sub flag {
90             shift->{flag}
91 16     16 1 30 }
92              
93             sub no {
94 6     6 1 29 shift->{no};
95             }
96              
97             sub pass {
98 0     0 1   shift->{pass};
99             }
100              
101             sub dump {
102 0     0 1   my ($self) = @_;
103              
104             return join ':',
105 0           grep { defined }
  0            
106             $self->function, $self->arg,
107             $self->pass, $self->no, $self->flag;
108             }
109              
110             1;