blib/lib/Linux/Proc/Mounts.pm

filter: Statementstmt 70.0% 49 / 70 Branchbran 50.0% 10 / 20 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 38.8% 7 / 18 Podpod 100% 4 / 4 totaltotal 59.0% 72 / 122 CC 17 SCAR 23.2
CC
17
Cov
64%
read
18.9
opts_hash
12.0
under
2.0
CRAP 10.2
↑ Summary
1 package Linux::Proc::Mounts;
2  
3 1 our $VERSION = '0.02';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub read {
Subroutine read: called CC=15 SCAR=29.4
Pod documented
10 1 my ($class, %opts) = @_;
11 1 my $mnt = delete $opts{mnt};
12 1 my $pid = delete $opts{pid};
13 1 my $file = delete $opts{file};
14 1 ▶ %opts and croak "Unknown option(s) ". join(", ", sort keys %opts);
Branch: 1 branch
BranchTrueFalseTotal
%opts and croak('Unknown option(s) ' . join(", ", sort(keys %opts))) 0 1 1
15  
16 1 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 1 0 1
17 1 ▶ $mnt = "/proc" unless defined $mnt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mnt 1 0 1
18 1 ▶ croak "$mnt is not a proc filesystem" unless -d $mnt and (stat _)[12] == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $mnt and (stat _)[12] == 0 0 1 1
Condition33%1/3
-d $mnt and (stat _)[12] == 0
!ll&&!rl&&r
001
MC/DC0%0/2
-d $mnt and (stat _)[12] == 0
-d $mnt (stat _)[12] == 0
Truth table33%1/3
A and B
A= -d $mntB= (stat _)[12] == 0
ABresult
0X0
100
111
19 1 ▶ $mnt .= "/$pid" if defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pid 0 1 1
20 1 $file = "$mnt/mounts";
21 }
22 1 ▶ open my $fh, '<', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or croak("Unable to open '${file}': $!") 1 0 1
23 or croak "Unable to open '$file': $!";
24  
25 1 my @entries;
26 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 24 1 25
27 24 chomp;
28 24 my @entry = split;
29 24 ▶ if (@entry != 6) {
Branch: 1 branch
BranchTrueFalseTotal
if (@entry != 6) 0 24 24
30 0 warn "invalid number of entries in $file line $.";
31 0 next;
32 }
33 24 $#entry = 3; # ignore the two dummy values at the end
34 24 s/\\([0-7]{1,3})/chr oct $1/g for @entry;
35 24 push @entry, _key($entry[1]);
36 24 push @entry, $.;
37 24 my $entry = \@entry;
38 24 bless $entry, 'Linux::Proc::Mounts::Entry';
39 24 push @entries, $entry;
40 }
41  
42 1 for my $i (1..$#entries) {
43 23 my $shadow = $entries[$i];
44 # my $re = quotemeta $shadow->[4];
45 # $re = qr/^$re/;
46 # for my $e (@entries[0..$i-1]) {
47 # $e->[6] = $shadow if $e->[4] =~ $re and not $e->[6];
48 # }
49 23 for my $e (@entries[0..$i-1]) {
50 276 ▶ $e->[6] = $shadow if $e->[4] eq $shadow->[4] and not $e->[6];
Branch: 1 branch
BranchTrueFalseTotal
if $e->[4] eq $shadow->[4] and not $e->[6] 0 276 276
Condition33%1/3
$e->[4] eq $shadow->[4] and not $e->[6]
!ll&&!rl&&r
27600
MC/DC0%0/2
$e->[4] eq $shadow->[4] and not $e->[6]
$e->[4] eq $shadow->[4] not $e->[6]
Truth table33%1/3
A and not(B)
A= $e->[4] eq $shadow->[4]B= not $e->[6]
ABresult
0X0
100
111
51 }
52 }
53 1 bless \@entries, $class;
54 }
55  
56 25 ▶sub _key {
Subroutine _key: called CC=1 SCAR=0.0
57 25 my $mnt = shift;
58 25 $mnt =~ s|/+|/|g;
59 25 $mnt =~ s|/?$|/|;
60 25 $mnt =~ s|([\0/])|\0$1|g;
61 25 $mnt;
62 }
63  
64 1 ▶sub at {
Subroutine at: called CC=1 SCAR=0.0
Pod documented
65 1 my ($self, $at) = @_;
66 1 my $key = _key $at;
67 1 bless [grep { $_->[4] eq $key } @$self], ref $self;
68 }
69  
70 0 ▶sub under {
Subroutine under: not called CC=1 SCAR=6.9
Pod documented
71 0 my ($self, $under) = @_;
72 0 my $key = quotemeta _key $under;
73 0 my $re = qr/^$key/;
74 0 bless [grep $_->[4] =~ $re, @$self], ref $self;
75 }
76  
77 1 ▶sub visible {
Subroutine visible: called CC=1 SCAR=0.0
Pod documented
78 1 my $self = shift;
79 1 bless [grep !$_->[6], @$self], ref $self;
80 }
81  
82 package Linux::Proc::Mounts::Entry;
83  
84 0 ▶sub _key { shift->[4] }
Subroutine _key: not called CC=1 SCAR=6.9
85 0 ▶sub spec { shift->[0] }
Subroutine spec: not called CC=1 SCAR=6.9
86 0 ▶sub file { shift->[1] }
Subroutine file: not called CC=1 SCAR=6.9
87 0 ▶sub fstype { shift->[2] }
Subroutine fstype: not called CC=1 SCAR=6.9
88 0 ▶sub opts { shift->[3] }
Subroutine opts: not called CC=1 SCAR=6.9
89 0 ▶sub ix { shift->[5] }
Subroutine ix: not called CC=1 SCAR=6.9
90 0 ▶sub shadower { shift->[6] }
Subroutine shadower: not called CC=1 SCAR=6.9
91  
92 0 ▶sub opts_hash {
Subroutine opts_hash: not called CC=3 SCAR=24.8
93 0 my %h;
94 0 for (split /,/, shift->[3]) {
95 0 ▶ if (/(.*)=(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(.*)=(.*)/) { } 0 0 0
96 0 $h{$1} = $2;
97 }
98 else {
99 0 $h{$_} = 1;
100 }
101 }
102 0 \%h;
103 }
104  
105 0 ▶sub is_ro { shift->[3] =~ /(?:^|,)ro(?:,|$)/ }
Subroutine is_ro: not called CC=1 SCAR=6.9
106  
107 0 ▶sub is_rw { shift->[3] =~ /(?:^|,)rw(?:,|$)/ }
Subroutine is_rw: not called CC=1 SCAR=6.9
108  
109  
110 __END__
↑ Summary