| 1 | package Linux::Proc::Mountinfo; | ||||||||||||||||||||||||||||
| 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 | 25 | ▶ | sub _key { | ||||||||||||||||||||||||||
|
Subroutine
_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 25 | my $mnt = shift; | |||||||||||||||||||||||||||
| 11 | 25 | $mnt =~ s|/+|/|g; | |||||||||||||||||||||||||||
| 12 | 25 | $mnt =~ s|/?$|/|; | |||||||||||||||||||||||||||
| 13 | 25 | $mnt =~ s|([\0/])|\0$1|g; | |||||||||||||||||||||||||||
| 14 | 25 | $mnt; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=18 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 1 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||
| 19 | 1 | my $mnt = delete $opts{mnt}; | |||||||||||||||||||||||||||
| 20 | 1 | my $pid = delete $opts{pid}; | |||||||||||||||||||||||||||
| 21 | 1 | my $file = delete $opts{file}; | |||||||||||||||||||||||||||
| 22 | 1 | ▶ | %opts and croak "Unknown option(s) ". join(", ", sort keys %opts); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | unless (defined $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | $mnt = "/proc" unless defined $mnt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | croak "'$mnt' is not a proc filesystem" unless -d $mnt and (stat _)[12] == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $mnt and (stat _)[12] == 0
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
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | $pid = $$ unless defined $pid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 1 | $file = "$mnt/$pid/mountinfo"; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 1 | ▶ | open my $fh, '<', $file or croak "Unable to open '$file': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | my @entries; | |||||||||||||||||||||||||||
| 33 | my %entry_by_id; | ||||||||||||||||||||||||||||
| 34 | 1 | my %entry_by_mm; | |||||||||||||||||||||||||||
| 35 | 1 | ▶ | OUT: while (<$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 24 | chomp; | |||||||||||||||||||||||||||
| 37 | 24 | my @fields = split; | |||||||||||||||||||||||||||
| 38 | 24 | my ($dash_ix) = grep $fields[$_] eq '-', 6 .. $#fields; | |||||||||||||||||||||||||||
| 39 | 24 | ▶ | unless ($dash_ix) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | warn "dash not found inside mountinfo"; | |||||||||||||||||||||||||||
| 41 | 0 | next; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 24 | ▶ | if (@fields < $dash_ix + 4) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | warn "invalid number of fields"; | |||||||||||||||||||||||||||
| 46 | 0 | next; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 24 | s/\\([0-7]{1,3})/chr oct $1/g for @fields; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 24 | my $entry = [ @fields[0 .. 5, $dash_ix+1 .. $#fields], | |||||||||||||||||||||||||||
| 52 | [ @fields[6 .. $dash_ix-1] ], | ||||||||||||||||||||||||||||
| 53 | $., $_, | ||||||||||||||||||||||||||||
| 54 | _key($fields[4]), | ||||||||||||||||||||||||||||
| 55 | [] ]; | ||||||||||||||||||||||||||||
| 56 | 24 | push @entries, bless $entry, 'Linux::Proc::Mountinfo::Entry'; | |||||||||||||||||||||||||||
| 57 | 24 | $entry_by_id{$entry->[0]} = $entry; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 24 | my $old = $entry_by_mm{$entry->[2]}; | |||||||||||||||||||||||||||
| 60 | 24 | ▶ | if (not $old or length($entry->[3]) < length($old->[3])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $old or length $entry->[3] < length $old->[3]
MC/DC100%2/2
not $old or length $entry->[3] < length $old->[3]
not $old
length $entry->[3] < length $old->[3]
Truth table100%3/3
not(A) or B
A= not $oldB= length $entry->[3] < length $old->[3]
| |||||||||||||||||||||||||||||
| 61 | 14 | $entry_by_mm{$entry->[2]} = $entry | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | for my $entry (@entries) { | |||||||||||||||||||||||||||
| 66 | 24 | my $bind = $entry_by_mm{$entry->[2]}; | |||||||||||||||||||||||||||
| 67 | 24 | ▶ | $entry->[14] = ( $bind == $entry ? undef : $bind ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 24 | ▶ | if ($entry->[0] != $entry->[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 24 | ▶ | if (my $parent = $entry_by_id{$entry->[1]}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 23 | push @{$parent->[13]}, $entry; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | bless \@entries, $class; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | *new = \&read; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | ▶ | sub at { | ||||||||||||||||||||||||||
|
Subroutine
at: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 1 | my ($self, $at) = @_; | |||||||||||||||||||||||||||
| 84 | 1 | my $key = _key $at; | |||||||||||||||||||||||||||
| 85 | 1 | ▶ | $_->[12] eq $key and return $_ for @$self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | () | ||||||||||||||||||||||||||||
| 87 | 0 | } | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub root { | ||||||||||||||||||||||||||
|
Subroutine
root: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | $_->[4] eq '/' and return $_ for @$self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | () | ||||||||||||||||||||||||||||
| 93 | 0 | } | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | package Linux::Proc::Mountinfo::Entry; | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub mount_id { shift->[ 0] } | ||||||||||||||||||||||||||
|
Subroutine
mount_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub parent_id { shift->[ 1] } | ||||||||||||||||||||||||||
|
Subroutine
parent_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub major_minor { shift->[ 2] } | ||||||||||||||||||||||||||
|
Subroutine
major_minor: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub root { shift->[ 3] } | ||||||||||||||||||||||||||
|
Subroutine
root: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 101 | 1 | ▶ | sub mount_point { shift->[ 4] } | ||||||||||||||||||||||||||
|
Subroutine
mount_point: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub mount_options { shift->[ 5] } | ||||||||||||||||||||||||||
|
Subroutine
mount_options: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub fs_type { shift->[ 6] } | ||||||||||||||||||||||||||
|
Subroutine
fs_type: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub mount_source { shift->[ 7] } | ||||||||||||||||||||||||||
|
Subroutine
mount_source: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub super_options { shift->[ 8] } | ||||||||||||||||||||||||||
|
Subroutine
super_options: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub optional_fields { [@{shift->[9]}] } | ||||||||||||||||||||||||||
|
Subroutine
optional_fields: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub line_number { shift->[10] } | ||||||||||||||||||||||||||
|
Subroutine
line_number: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub line { shift->[11] } | ||||||||||||||||||||||||||
|
Subroutine
line: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub _key { shift->[12] } | ||||||||||||||||||||||||||
|
Subroutine
_key: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub major { (split /:/, shift->[2])[0] } | ||||||||||||||||||||||||||
|
Subroutine
major: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub minor { (split /:/, shift->[2])[1] } | ||||||||||||||||||||||||||
|
Subroutine
minor: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub children { bless [@{shift->[13]}], 'Linux::Proc::Mountinfo' } | ||||||||||||||||||||||||||
|
Subroutine
children: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub bind_source { shift->[14] } | ||||||||||||||||||||||||||
|
Subroutine
bind_source: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub flatten { | ||||||||||||||||||||||||||
|
Subroutine
flatten: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 122 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | 0 | my @flatten; | |||||||||||||||||||||||||||
| 124 | 0 | my @queue = $self; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | while (@queue) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | my $first = shift @queue; | |||||||||||||||||||||||||||
| 127 | 0 | push @flatten, $first; | |||||||||||||||||||||||||||
| 128 | 0 | push @queue, @{$first->[13]} | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | bless \@flatten, 'Linux::Proc::Mountinfo' | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 1 | 1; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | __END__ | ||||||||||||||||||||||||||||