File Coverage

blib/lib/Getopt/Yath/Settings/Group.pm
Criterion Covered Total %
statement 20 44 45.4
branch 2 16 12.5
condition 1 3 33.3
subroutine 6 13 46.1
pod 7 9 77.7
total 36 85 42.3


line stmt bran cond sub pod time code
1             package Getopt::Yath::Settings::Group;
2 1     1   5 use strict;
  1         1  
  1         29  
3 1     1   4 use warnings;
  1         1  
  1         58  
4              
5             our $VERSION = '2.000007';
6              
7 1     1   4 use Carp();
  1         2  
  1         619  
8              
9             sub new {
10 62     62 0 76 my $class = shift;
11 62 50       121 my $self = (@_ != 1) ? { @_ } : $_[0];
12              
13 62         191 return bless($self, $class);
14             }
15              
16 0     0 1 0 sub all { return %{$_[0]} }
  0         0  
17              
18 0 0   0 1 0 sub check_option { exists($_[0]->{$_[1]}) ? 1 : 0 }
19              
20             sub option :lvalue {
21 0     0 1 0 my $self = shift;
22 0         0 my ($option, @vals) = @_;
23              
24 0 0       0 Carp::confess("Too many arguments for option()") if @vals > 1;
25 0 0       0 Carp::confess("The '$option' option does not exist") unless exists $self->{$option};
26              
27 0 0       0 ($self->{$option}) = @vals if @vals;
28              
29 0         0 return $self->{$option};
30             }
31              
32             sub create_option {
33 0     0 1 0 my $self = shift;
34 0         0 my ($name, $val) = @_;
35              
36 0         0 $self->{$name} = $val;
37              
38 0         0 return $self->{$name};
39             }
40              
41             sub option_ref {
42 1426     1426 1 1917 my $self = shift;
43 1426         1981 my ($name, $create) = @_;
44              
45 1426 0 33     2211 Carp::confess("The '$name' option does not exist") unless $create || exists $self->{$name};
46              
47 1426         2603 return \($self->{$name});
48             }
49              
50             sub delete_option {
51 0     0 1 0 my $self = shift;
52 0         0 my ($name) = @_;
53              
54 0         0 delete $self->{$name};
55             }
56              
57             sub remove_option {
58 0     0 1 0 my $self = shift;
59 0         0 my ($name) = @_;
60 0         0 delete ${$self}->{$name};
  0         0  
61             }
62              
63             our $AUTOLOAD;
64             sub AUTOLOAD : lvalue {
65 62     62   85 my $this = shift;
66              
67 62         85 my $option = $AUTOLOAD;
68 62         167 $option =~ s/^.*:://g;
69              
70 62 50       626 return if $option eq 'DESTROY';
71              
72 0 0         Carp::confess("Method $option() must be called on a blessed instance") unless ref($this);
73              
74 0           $this->option($option, @_);
75             }
76              
77             sub TO_JSON {
78 0     0 0   my $self = shift;
79 0           return {%$self};
80             }
81              
82             1;
83              
84             __END__