Lufs/Stub.pm untested

filter: Statementstmt 0.0% 0 / 73 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 112 CC 8 SCAR 21.5
CC
8
Cov
0%
stat
20.0
read
12.0
readdir
6.0
CRAP 8.6
1 package Lufs::Stub;
2  
3 sub init {
4 my $self = shift;
5 my $arg = shift;
6  
7 return 1;
8 }
9  
10 sub AUTOLOAD {
11 my $self = shift;
12 my $method = (split/::/,$AUTOLOAD)[-1];
13 $method eq 'DESTROY' && return;
14 $self->TRACE("$method not implemented: $_[0]");
15 0;
16 }
17  
18 #####################################
19 ############# lufs calls ############
20 #####################################
21  
22 sub mount {
23 my $self = shift;
24 return 1;
25 }
26  
27 sub umount {
28 my $self = shift;
29 return 1;
30 }
31  
32 sub stat {
33 my $self = shift;
34 my $file = shift;
35 $file =~ s{/\.$}{/};
36 my $ref = shift;
37 if ($file eq '/') {
38 $ref->{f_ino} = 1;
39 $ref->{f_mode} = 0040000 | 0755;
40 $ref->{f_nlink} = 1;
41 $ref->{f_uid} = 0;
42 $ref->{f_gid} = 0;
43 $ref->{f_size} = 2048;
44 $ref->{f_atime} = time;
45 $ref->{f_mtime} = time;
46 $ref->{f_ctime} = time;
47 $ref->{f_blksize} = 512;
48 $ref->{f_blocks} = 4;
49 return 1;
50 }
51 elsif ($file =~ /(hello|world)/) {
52 $ref->{f_ino} = $file eq 'hello'?2:3;
53 $ref->{f_mode} = 0100000 | 0666;
54 $ref->{f_nlink} = 1;
55 $ref->{f_uid} = 1;
56 $ref->{f_gid} = 1;
57 $ref->{f_size} = 4096;
58 $ref->{f_atime} = time;
59 $ref->{f_mtime} = time;
60 $ref->{f_ctime} = time;
61 $ref->{f_blksize} = 512;
62 $ref->{f_blocks} = 8;
63 return 1;
64 }
65 return 0;
66 }
67  
68 sub readdir {
69 my $self = shift;
70 my $dir = shift;
71 my $ref = shift;
72 if ($dir eq '/') {
73 push @{$ref}, qw/hello world/;
74 }
75 }
76  
77 sub mkdir {
78 my $self = shift;
79 my $dir = shift;
80 my $mode = shift;
81 return -1;
82 }
83  
84 sub open {
85 my $self = shift;
86 my ($file,$mode) = @_;
87 if ($file =~ /(?:hello|world)/) {
88 return 1;
89 }
90 return 0;
91 }
92  
93 sub read {
94 my $self = shift;
95 my $file = shift;
96 my $offset = shift;
97 my $count = shift;
98 unless ($file =~ /(hello|world)/) { return 0 }
99 if ($offset > 4096) { return 0 }
100 $_[0] = "$1 "x($count/6);
101 return $count;
102 }
103  
104 sub release {
105 my $self = shift;
106 my ($file) = shift;
107 return 1;
108 }
109  
110 sub write {
111 my $self = shift;
112 my ($file, $offset, $count, $buf) = @_;
113 return length($buf);
114 }
115  
116 1;
117 __END__