File Coverage

blib/lib/App/revealup/base.pm
Criterion Covered Total %
statement 34 34 100.0
branch 9 10 90.0
condition n/a
subroutine 9 9 100.0
pod 0 1 0.0
total 52 54 96.3


line stmt bran cond sub pod time code
1             package App::revealup::base;
2 7     7   58241 use strict;
  7         32  
  7         177  
3 7     7   29 use warnings;
  7         10  
  7         237  
4              
5             sub import {
6 18     18   70 my $caller = caller(0);
7 7     7   33 no strict 'refs';
  7         8  
  7         1239  
8 18     59   72 *{"${caller}::has"} = sub { attr($caller, @_) };
  18         89  
  59         118  
9 18         59 *{"${caller}::new"} = sub {
10 14     14   6732 my ($klass, %opt) = @_;
11 14         54 for my $key (keys %opt) {
12 10 100       30 attr($caller, $key, $opt{$key}) if $opt{$key};
13             }
14 14         38 return bless \%opt, $klass;
15 18         60 };
16 18         94 strict->import;
17 18         830 warnings->import;
18             }
19              
20             sub attr {
21 64     64 0 140 my ( $caller, $k, $v ) = @_;
22 7     7   52 no strict 'refs';
  7         9  
  7         826  
23 64 100       74 return if defined *{"${caller}::$k"};
  64         306  
24 60         242 *{"${caller}::$k"} = sub {
25 64     64   803 my ( $self, $value ) = @_;
26 64 100       151 if ( !$value ) {
27 61 100       170 $self->{$k} = $v if !$self->{$k};
28 61         225 return $self->{$k};
29             }
30 3 50       14 $self->{$k} = $value if $value;
31 60         177 };
32             }
33              
34             1;