Ramdisk.pm

filter: Statementstmt 46.5% 34 / 73 Branchbran 13.6% 3 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 61.5% 8 / 13 Podpod 33.3% 2 / 6 totaltotal 40.3% 48 / 119 CC 14 SCAR 22.8
CC
14
Cov
39%
os_supported_list
30.0
new
12.0
dir
6.0
CRAP 9.8
« Ramdisk/OSX.pm ↑ Summary
1 ###########################################
2 package Sys::Ramdisk;
3 ###########################################
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Log::Log4perl qw(:easy);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Sysadm::Install qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = "0.02";
12  
13 my %class_mapper =
14 1 map { $_->[0] => __PACKAGE__ . "::" . $_->[1] }
15 ( [linux => "Linux"],
16 [macos => "OSX"],
17 [osx => "OSX"],
18 [darwin => "OSX"],
19 );
20  
21 ###########################################
22 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
23 ###########################################
24 0 my($class, %options) = @_;
25  
26 0 my $self = {
27 cleanup => 1,
28 %options,
29 };
30  
31 0 ▶ if(! defined $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dir"}) 0 0 0
32 0 $self->{dir} = tempdir( CLEANUP => 1 );
33 }
34  
35 0 ▶ if(! defined $self->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"size"}) 0 0 0
36 0 $self->{size} = "100m";
37 }
38  
39 0 my $subclass = os_class_find();
40  
41 0 eval "require $subclass";
42  
43 0 bless $self, $subclass;
44  
45 0 return $self;
46 }
47  
48 ###########################################
49 0 ▶sub os_supported_list {
Subroutine os_supported_list: not called CC=5 SCAR=34.0
Pod undocumented
50 ###########################################
51 0 (my $path = __PACKAGE__) =~ s/::/\//g;
52 0 $path = "$path.pm";
53  
54 0 my $dir = $INC{$path};
55 0 $dir =~ s/\.pm$//;
56  
57 0 my @classes = ();
58  
59 0 ▶ opendir DIR, "$dir" or LOGDIE "Cannot opendir $dir ($!)";
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, "$dir" or LOGDIE("Cannot opendir $dir ($!)") 0 0 0
60 0 for my $dir (readdir DIR) {
61 0 ▶ next if $dir eq ".";
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "." 0 0 0
62 0 ▶ next if $dir eq "..";
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq ".." 0 0 0
63 0 $dir =~ s/\.pm$//;
64 0 push @classes, $dir;
65 }
66  
67 0 closedir DIR;
68  
69 0 return @classes;
70 }
71  
72 ###########################################
73 2 ▶sub os_find {
Subroutine os_find: called CC=4 SCAR=17.3
Pod undocumented
74 ###########################################
75 2 my $uname = bin_find("uname");
76  
77 2 ▶ if(! defined $uname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $uname) 0 2 2
78 0 LOGWARN "uname command not found in PATH";
79 0 return undef;
80 }
81  
82 2 my($uname_info) = tap $uname;
83 2 chomp $uname_info;
84  
85 2 ▶ if(! defined $uname or length $uname == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $uname or length $uname == 0) 0 2 2
Condition33%1/3
not defined $uname or length $uname == 0
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $uname or length $uname == 0
not defined $uname length $uname == 0
Truth table33%1/3
not(A) or B
A= not defined $unameB= length $uname == 0
ABresult
1X1
011
000
86 0 LOGWARN "uname didn't return anything meaningful";
87 0 return undef;
88 }
89  
90 2 return $uname_info;
91 }
92  
93 ###########################################
94 1 ▶sub os_class_find {
Subroutine os_class_find: called CC=2 SCAR=7.5
Pod undocumented
95 ###########################################
96 1 my $os = os_find();
97  
98 1 my $keyword = lc $os;
99  
100 1 ▶ if(exists $class_mapper{ $keyword }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $class_mapper{$keyword}) 1 0 1
101 1 my $class = $class_mapper{ $keyword };
102  
103 1 DEBUG "Found class $class";
104 1 return $class;
105 }
106  
107 0 WARN "OS '$os' not supported (yet). Please contact the maintainer";
108 0 return undef;
109 }
110  
111 ###########################################
112 0 ▶sub dir {
Subroutine dir: not called CC=2 SCAR=17.9
Pod documented
113 ###########################################
114 0 my($self, $dir) = @_;
115  
116 0 ▶ if(defined $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 0 0 0
117 0 $self->{dir} = $dir;
118 }
119  
120 0 return $self->{dir};
121 }
122  
123 ###########################################
124 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
125 ###########################################
126 0 my($self, $dir) = @_;
127  
128 0 ▶ $self->unmount() if $self->{cleanup};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cleanup"} 0 0 0
129 }
130  
131 ###########################################
132 0 ▶sub size_normalize {
Subroutine size_normalize: not called CC=2 SCAR=17.9
Pod undocumented
133 ###########################################
134 0 my($self, $size) = @_;
135  
136 0 ▶ if($size =~ /(\d+)m/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size =~ /(\d+)m/) 0 0 0
137 0 return $1 * 1024 * 1024;
138 }
139  
140 0 return $size;
141 }
142  
143 1 1;
144  
145 __END__
« Ramdisk/OSX.pm ↑ Summary