File Coverage

blib/lib/Acme/Oil.pm
Criterion Covered Total %
statement 55 60 91.6
branch 24 34 70.5
condition 1 2 50.0
subroutine 11 11 100.0
pod 2 5 40.0
total 93 112 83.0


line stmt bran cond sub pod time code
1             package Acme::Oil;
2             ##############################################################################
3              
4 3     3   106481 use strict;
  3         9  
  3         114  
5 3     3   15 use warnings;
  3         7  
  3         87  
6 3     3   15 use warnings::register;
  3         11  
  3         639  
7 3     3   16 use Carp;
  3         6  
  3         283  
8 3     3   16 use vars qw($VERSION);
  3         4  
  3         2333  
9              
10             my $Level = 100; # remainder
11              
12             $VERSION= 0.1;
13             ##############################################################################
14              
15             sub can (;\[$@%]){ # UNIVERSAL::can is overloaded!
16              
17 13 100   13 1 5226 return $Level unless(@_ > 0);
18              
19 7 50       23 return 0 if(!$Level); # oil can is empty!
20              
21 7 100       22 if( is_this_burning($_[0]) ){
22 2         12 ignition($_[0]);
23 2         6 $Level = 0;
24             }
25             else{
26 5         17 soak( $_[0] );
27 5         7 --$Level;
28             }
29              
30 7         11 $Level;
31             }
32              
33              
34             sub wipe (\[$@%]) {
35 3 100   3 1 18 if(ref($_[0]) eq 'SCALAR'){
    50          
    0          
36 1         2 untie ${$_[0]};
  1         14  
37             }
38             elsif(ref($_[0]) eq 'ARRAY'){
39 2         3 untie @{$_[0]};
  2         15  
40             }
41             elsif(ref($_[0]) eq 'HASH'){
42 0         0 untie %{$_[0]};
  0         0  
43             }
44             else{
45 0         0 croak "Sorry, not support it.";
46             }
47             }
48              
49              
50             sub soak {
51 5 100   5 0 17 if(ref($_[0]) eq 'SCALAR'){
    50          
    0          
52 2         613 require Acme::Oil::ed::Scalar;
53 2         3 tie ${$_[0]}, 'Acme::Oil::ed::Scalar', ${$_[0]};
  2         4  
  2         21  
54             }
55             elsif(ref($_[0]) eq 'ARRAY'){
56             #croak "Sorry, not yet implemented.";
57 3         731 require Acme::Oil::ed::Array;
58 3         4 tie @{$_[0]}, 'Acme::Oil::ed::Array', @{$_[0]};
  3         6  
  3         17  
59             }
60             elsif(ref($_[0]) eq 'HASH'){
61 0         0 croak "Sorry, not yet implemented.";
62             #tie ${$_[0]}, 'Acme::Oil::ed::HASH', ${$_[0]};
63             }
64             else{
65 0         0 croak "Sorry, not support it.";
66             }
67             }
68              
69              
70             sub is_this_burning {
71 7   50 7 0 21 my $ref = shift || return 0;
72              
73 7 100       31 if(ref($ref) eq 'SCALAR'){
    50          
74 3         7 return _is_burning($$ref);
75             }
76             elsif(ref($ref) eq 'ARRAY'){
77 4         9 for my $value (@$ref){
78 7 100       10 if(_is_burning($value)){ return 1; }
  1         3  
79             }
80 3         7 return 0;
81             }
82             }
83              
84              
85             sub _is_burning {
86 45     45   51 my $value = shift;
87 45 100       181 return 0 unless(defined $value);
88 42 100       178 return 1 if $value =~ /fire/i;
89             }
90              
91              
92             sub ignition {
93              
94 2 50   2 0 389 carp "Don't bring the fire close! ...Bom!"
95             if(warnings::enabled('Acme::Oil'));
96              
97 2 100       64 if(ref($_[0]) eq 'SCALAR'){
    50          
98 1         6 require Acme::Oil::Ashed::Scalar;
99 1         1 tie ${$_[0]}, 'Acme::Oil::Ashed::Scalar';
  1         6  
100             }
101             elsif(ref($_[0]) eq 'ARRAY'){
102 1         5 require Acme::Oil::Ashed::Array;
103 1         2 tie @{$_[0]}, 'Acme::Oil::Ashed::Array';
  1         9  
104             }
105             }
106              
107             ##############################################################################
108             1;
109             __END__