File Coverage

blib/lib/Perinci/Object/Function.pm
Criterion Covered Total %
statement 51 51 100.0
branch 10 10 100.0
condition 9 16 56.2
subroutine 10 10 100.0
pod 6 6 100.0
total 86 93 92.4


line stmt bran cond sub pod time code
1             package Perinci::Object::Function;
2              
3             our $DATE = '2017-02-03'; # DATE
4             our $VERSION = '0.30'; # VERSION
5              
6 1     1   21 use 5.010;
  1         3  
7 1     1   4 use strict;
  1         1  
  1         21  
8 1     1   3 use warnings;
  1         1  
  1         31  
9              
10 1     1   380 use parent qw(Perinci::Object::Metadata);
  1         240  
  1         4  
11              
12 1     1 1 8 sub type { "function" }
13              
14             # convenience for accessing features property
15             sub feature {
16 7     7 1 52 my $self = shift;
17 7         7 my $name = shift;
18 7 100       14 if (@_) {
19 2 100       6 die "1.0 can't set feature" if $self->v eq 1.0;
20 1         2 my $value = shift;
21 1   50     1 ${$self}->{features} //= {};
  1         4  
22 1         1 my $old = ${$self}->{features}{$name};
  1         5  
23 1         3 ${$self}->{features}{$name} = $value;
  1         3  
24 1         3 return $old;
25             } else {
26 5         6 ${$self}->{features}{$name};
  5         40  
27             }
28             }
29              
30             sub features {
31 2     2 1 10 my $self = shift;
32 2   100     2 ${$self}->{features} // {};
  2         14  
33             }
34              
35             # transaction can be used to emulate dry run, by calling with -tx_action =>
36             # 'check_state' only
37             sub can_dry_run {
38 2     2 1 9 my $self = shift;
39 2   50     2 my $ff = ${$self}->{features} // {};
  2         7  
40 2   33     22 $ff->{dry_run} // $ff->{tx} && $ff->{tx}{v} == 2;
      66        
41             }
42              
43             sub default_dry_run {
44 4     4 1 16 my $self = shift;
45 4   50     3 my $ff = ${$self}->{features} // {};
  4         11  
46 4 100       20 ref($ff->{dry_run}) eq 'HASH' && $ff->{dry_run}{default};
47             }
48              
49             # convenience for accessing args property
50             sub arg {
51 7     7 1 24 my $self = shift;
52 7         6 my $name = shift;
53 7 100       16 if (@_) {
54 2 100       6 die "1.0 can't set arg" if $self->v eq 1.0;
55 1         3 my $value = shift;
56 1   50     1 ${$self}->{args} //= {};
  1         3  
57 1         2 my $old = ${$self}->{args}{$name};
  1         1  
58 1         2 ${$self}->{args}{$name} = $value;
  1         2  
59 1         3 return $old;
60             } else {
61 5         4 ${$self}->{args}{$name};
  5         24  
62             }
63             }
64              
65             1;
66             # ABSTRACT: Represent function metadata
67              
68             __END__