line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VFSsimple::Base; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
679
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
1362
|
use File::Temp qw(tempfile); |
|
1
|
|
|
|
|
30162
|
|
|
1
|
|
|
|
|
68
|
|
6
|
1
|
|
|
1
|
|
866
|
use IO::File; |
|
1
|
|
|
|
|
1148
|
|
|
1
|
|
|
|
|
181
|
|
7
|
1
|
|
|
1
|
|
12
|
use base qw(VFSsimple); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
892
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
VFSsimple::Base |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
A based module for any VFSimple driver. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package VFSsimple::Drv::Any; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use base qw(VFSsimple::Base); |
22
|
|
|
|
|
|
|
use File::Copy; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub drv_new { |
27
|
|
|
|
|
|
|
my ($self) = @_; |
28
|
|
|
|
|
|
|
... |
29
|
|
|
|
|
|
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub drv_get { |
33
|
|
|
|
|
|
|
my ($self, $src) = @_; |
34
|
|
|
|
|
|
|
return $self->{realroot} . '/' . $src; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub drv_copy { |
38
|
|
|
|
|
|
|
my ($self, $src, $dest) = @_; |
39
|
|
|
|
|
|
|
return File::Copy::copy($self->{realroot} . '/' . $src, $dest) ? $dest : (); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
1
|
|
|
1
|
1
|
3
|
my ($class, $root, $options) = @_; |
48
|
1
|
|
|
|
|
4
|
my $fs = { |
49
|
|
|
|
|
|
|
root => $root, |
50
|
|
|
|
|
|
|
options => $options, |
51
|
|
|
|
|
|
|
}; |
52
|
1
|
|
|
|
|
3
|
bless($fs, $class); |
53
|
1
|
|
|
|
|
6
|
return $fs->drv_new(); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 PROVIDED FUNCTIONS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 set_error($fmt, ...) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Store last error message |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub set_error { |
65
|
0
|
|
|
0
|
1
|
0
|
my ($self, $fmt, @args) = @_; |
66
|
0
|
|
|
|
|
0
|
$self->{_error} = sprintf($fmt, @args); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 root |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Return the root url of the VFS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub root { |
76
|
1
|
|
|
1
|
1
|
736
|
my ($self) = @_; |
77
|
1
|
|
|
|
|
12
|
return $self->{root}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 archive_path |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
If VFS handle a tree inside an archive, return the path of this archive. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub archive_path { |
87
|
1
|
|
|
1
|
1
|
3
|
my ($self) = @_; |
88
|
1
|
|
|
|
|
25
|
return $self->{options}{rootfile} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 archive_path |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
If VFS handle a tree inside an archive, return the virtual root path inside |
94
|
|
|
|
|
|
|
the archive. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub archive_subpath { |
99
|
1
|
|
|
1
|
0
|
422
|
my ($self) = @_; |
100
|
1
|
|
|
|
|
5
|
return $self->{options}{subpath} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 FUNCTIONS PROVIDED BY DRIVER |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 drv_new |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This function is called during object creation (new). It receive as arguments |
108
|
|
|
|
|
|
|
the fresh blessed object and allow the driver to load data it will need to |
109
|
|
|
|
|
|
|
work. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Should return the object in case of success, nothing on error. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub drv_new { |
116
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
117
|
1
|
|
|
|
|
4
|
return $self; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 drv_copy($source, $dest) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This function should copy $source relative path from vfs to $dest local path. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Should return True on success. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub drv_copy { |
129
|
0
|
|
|
0
|
1
|
|
my ($self, $src, $dest) = @_; |
130
|
0
|
|
|
|
|
|
$self->set_error("no drv_copy support"); |
131
|
0
|
|
|
|
|
|
return; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 drv_get($src) |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Should return any file path where the file can be locally found, nothing on |
137
|
|
|
|
|
|
|
error. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
If this function is not provided, a default from L is provided |
140
|
|
|
|
|
|
|
generating a temporary file and using drv_copy() to fetch it. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub drv_get { |
145
|
0
|
|
|
0
|
1
|
|
my ($self, $src) = @_; |
146
|
0
|
|
|
|
|
|
my (undef, $dest) = File::Temp::tempfile(UNLINK => 0); |
147
|
0
|
|
|
|
|
|
return $self->drv_copy($src, $dest); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 drv_open($src) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Should return a B file handle for relative path $src. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
If the function is not provide, default return an open file handle over a |
155
|
|
|
|
|
|
|
deleted temp file using drv_copy to fetch the file. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub drv_open { |
160
|
0
|
|
|
0
|
1
|
|
my ($self, $src) = @_; |
161
|
0
|
0
|
|
|
|
|
my $dest = $self->drv_get($src) or return; |
162
|
0
|
0
|
|
|
|
|
CORE::open(my $tmpfile, '<', $dest) or return; |
163
|
0
|
|
|
|
|
|
return $tmpfile; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 drv_exists($file) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Should true if $file exists |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub drv_exists { |
173
|
0
|
|
|
0
|
1
|
|
my ($self, $file) = @_; |
174
|
0
|
|
|
|
|
|
$self->set_error("no drv_exists support"); |
175
|
0
|
|
|
|
|
|
return; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
__END__ |