POSIX/Mem/Inode.pm

filter: Statementstmt 100% 59 / 59 Branchbran 94.4% 17 / 18 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 7 totaltotal 92.3% 96 / 104 CC 11 SCAR 9.9
CC
11
Cov
99%
new
6.0
open
3.0
child
2.0
CRAP 2.7
« POSIX/Userland/Test.pm ↑ Summary POSIX/FdTable.pm »
1 # Copyright (c) 2014, cPanel, Inc.
2 # All rights reserved.
3 # http://cpanel.net/
4 #
5 # This is free software; you can redistribute it and/or modify it under the same
6 # terms as Perl itself. See the LICENSE file for further details.
7  
8 package Filesys::POSIX::Mem::Inode;
9  
10 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 27 ▶use Filesys::POSIX::Bits;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 27 ▶use Filesys::POSIX::Inode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 27 ▶use Filesys::POSIX::Directory::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 27 ▶use Filesys::POSIX::Mem::Bucket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 27 ▶use Filesys::POSIX::Mem::Directory ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 27 ▶use Filesys::POSIX::Error qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 27 our @ISA = qw(Filesys::POSIX::Inode);
22  
23 289 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod undocumented
24 289 my ( $class, %opts ) = @_;
25 289 my $now = time;
26  
27 my $inode = bless {
28 'size' => 0,
29 'atime' => $now,
30 'mtime' => $now,
31 'ctime' => $now,
32 'uid' => 0,
33 'gid' => 0,
34 'mode' => defined $opts{'mode'} ? $opts{'mode'} : 0,
35 'dev' => $opts{'dev'},
36 'rdev' => defined $opts{'rdev'} ? $opts{'rdev'} : 0,
37 289 ▶ 'parent' => $opts{'parent'}
Branch: 2 branches
BranchTrueFalseTotal
defined $opts{'mode'} ? : 288 1 289
defined $opts{'rdev'} ? : 0 289 289
38 }, $class;
39  
40 289 ▶ if ( exists $opts{'mode'} && ( $opts{'mode'} & $S_IFMT ) == $S_IFDIR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"mode"} and ($opts{"mode"} & $Filesys::POSIX::Mem::Inode::S_IFMT) == $Filesys::POSIX::Mem::Inode::S_IFDIR) 177 112 289
Condition100%3/3
exists $opts{"mode"} and ($opts{"mode"} & $Filesys::POSIX::Mem::Inode::S_IFMT) == $Filesys::POSIX::Mem::Inode::S_IFDIR
!ll&&!rl&&r
1111177
MC/DC100%2/2
exists $opts{"mode"} and ($opts{"mode"} & $Filesys::POSIX::Mem::Inode::S_IFMT) == $Filesys::POSIX::Mem::Inode::S_IFDIR
exists $opts{"mode"} ($opts{"mode"} & $Filesys::POSIX::Mem::Inode::S_IFMT) == $Filesys::POSIX::Mem::Inode::S_IFDIR
Truth table100%3/3
A and B
A= exists $opts{"mode"}B= ($opts{"mode"} & $Filesys::POSIX::Mem::Inode::S_IFMT) == $Filesys::POSIX::Mem::Inode::S_IFDIR
ABresult
0X0
100
111
41 $inode->{'directory'} = Filesys::POSIX::Mem::Directory->new(
42 '.' => $inode,
43 177 ▶ '..' => $opts{'parent'} ? $opts{'parent'} : $inode
Branch: 1 branch
BranchTrueFalseTotal
$opts{'parent'} ? : 132 45 177
44 );
45 }
46  
47 289 return $inode;
48 }
49  
50 235 ▶sub child {
Subroutine child: called CC=2 SCAR=6.9
Pod undocumented
51 235 my ( $self, $name, $mode ) = @_;
52 235 my $directory = $self->directory;
53  
54 235 ▶ throw &Errno::EEXIST if $directory->exists($name);
Branch: 1 branch
BranchTrueFalseTotal
if $directory->exists($name) 1 234 235
55  
56 my $child = __PACKAGE__->new(
57 'mode' => $mode,
58 234 'dev' => $self->{'dev'},
59 'parent' => $directory->get('.')
60 );
61  
62 234 $directory->set( $name, $child );
63  
64 234 return $child;
65 }
66  
67 2 ▶sub chown {
Subroutine chown: called CC=1 SCAR=0.0
Pod undocumented
68 2 my ( $self, $uid, $gid ) = @_;
69 2 @{$self}{qw(uid gid)} = ( $uid, $gid );
70 }
71  
72 16 ▶sub chmod {
Subroutine chmod: called CC=1 SCAR=0.0
Pod undocumented
73 16 my ( $self, $mode ) = @_;
74 16 my $format = $self->{'mode'} & $S_IFMT;
75 16 my $perm = $mode & ( $S_IPERM | $S_IPROT );
76  
77 16 $self->{'mode'} = $format | $perm;
78 }
79  
80 16 ▶sub readlink {
Subroutine readlink: called CC=2 SCAR=6.9
Pod undocumented
81 16 my ($self) = @_;
82  
83 16 ▶ throw &Errno::EINVAL unless $self->link;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->link 1 15 16
84  
85 15 return $self->{'dest'};
86 }
87  
88 16 ▶sub symlink {
Subroutine symlink: called CC=2 SCAR=6.9
Pod undocumented
89 16 my ( $self, $dest ) = @_;
90  
91 16 ▶ throw &Errno::EINVAL unless $self->link;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->link 1 15 16
92  
93 15 $self->{'dest'} = $dest;
94  
95 15 return $self;
96 }
97  
98 79 ▶sub open {
Subroutine open: called CC=3 SCAR=11.0
Pod undocumented
99 79 my ( $self, $flags ) = @_;
100  
101 79 ▶ if ( $self->dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dir) 2 77 79
102 2 return Filesys::POSIX::Directory::Handle->new;
103 }
104  
105 77 my $dev_flags = $self->{'dev'}->{'flags'};
106  
107 77 ▶ unless ( $self->{'bucket'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"bucket"}) 60 17 77
108 $self->{'bucket'} = Filesys::POSIX::Mem::Bucket->new(
109 'inode' => $self,
110 'max' => $dev_flags->{'bucket_max'},
111 60 'dir' => $dev_flags->{'bucket_dir'}
112 );
113 }
114  
115 77 return $self->{'bucket'}->open($flags);
116 }
117  
118 27 1;
« POSIX/Userland/Test.pm ↑ Summary POSIX/FdTable.pm »