File Coverage

blib/lib/Acme/Crap.pm
Criterion Covered Total %
statement 44 44 100.0
branch 8 8 100.0
condition n/a
subroutine 15 15 100.0
pod 0 1 0.0
total 67 68 98.5


line stmt bran cond sub pod time code
1             package Acme::Crap;
2 2     2   231196 use 5.010;
  2         7  
3              
4             our $VERSION = '0.001003';
5              
6 2     2   16 use warnings;
  2         14  
  2         169  
7 2     2   12 use strict;
  2         23  
  2         50  
8 2     2   8 use Carp;
  2         14  
  2         337  
9              
10 27     27 0 133292 sub deref { my ($self) = @_; return ${$self}; }
  27         29  
  27         124  
11              
12             use overload (
13 9     9   13 q{!} => sub { Acme::Crap::Negated->new(&deref) },
14 2         19 q{""} => \&deref,
15             q{0+} => \&deref,
16             q{bool} => \&deref,
17              
18             fallback => 1,
19 2     2   1392 );
  2         3739  
20              
21             sub import {
22 27     27   40 overload::constant q => sub { my $val = $_[1]; bless \$val, 'Acme::Crap' };
  27     2   1587  
  2         25  
23              
24 2     2   292 no strict qw( refs );
  2         3  
  2         878  
25 2         43 *{caller().'::crap'} = sub {
26 5     5   27 local $Acme::Crap::no_negation = 1;
27 5         11 @_ = map {"$_"} @_;
  5         15  
28 5         757 goto &Carp::carp;
29             }
30 2         49 }
31              
32             package Acme::Crap::Negated;
33              
34             sub new {
35 9     9   12 my ($class, $val) = @_;
36 9         99 bless { val => $val, degree => 1 }, $class;
37             }
38              
39             sub value {
40 9     9   3133 my ($self) = @_;
41 9 100       30 if ($Acme::Crap::no_negation) {
42             return $self->{degree} == 1 ? ucfirst "$self->{val}!"
43 7         22 : $self->{degree} == 2 ? join q{}, map { ucfirst $_ } split /(\s+)/, "$self->{val}!!"
44 4 100       47 : uc $self->{val} . '!' x $self->{degree};
    100          
45             }
46 5 100       33 return !$self->{val} if $self->{degree} % 2;
47 2         14 return !!$self->{val};
48             }
49              
50             use overload (
51 17     17   17 q{!} => sub { my ($self) = @_; $self->{degree}++; return $self; },
  17         16  
  17         162  
52 2         17 q{""} => \&value,
53             q{0+} => \&value,
54             q{bool} => \&value,
55              
56             fallback => 1,
57 2     2   15 );
  2         3  
58              
59             1; # Magic true value required at end of module
60              
61             __END__