line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VFSsimple; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
664
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
1777
|
use URI; |
|
2
|
|
|
|
|
10871
|
|
|
2
|
|
|
|
|
609
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
VFSsimple |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
A library to magically access to file w/o carry the method |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $vfs = VFSsimple->new($url) |
20
|
|
|
|
|
|
|
or die "can't get the vfs"; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$vfs->copy("path/fichier", "/tmp/fichier") |
23
|
|
|
|
|
|
|
or die "can't get file"; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 FUNCTIONS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 new($root, $options) |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Instanciate a new VFSimple object over $root url. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$root The root of the vfs |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$options is a hashref: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=over 4 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item vfs |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Force the virtal access method to use |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=back |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head3 url parsing |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The $root should be a valid url: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
protocol://server/path |
48
|
|
|
|
|
|
|
file://path |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
A standard file path can also be used, understood as file://. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
The access method to use is find automatically using url infromation: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
- protocol from url |
55
|
|
|
|
|
|
|
- if protocol is either file:// or ext:// and target is a file, the extension |
56
|
|
|
|
|
|
|
is use. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
The automatic behavior can overide by setting vfs option. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
For local file abstraction, an additionnal path can be append to set the root |
61
|
|
|
|
|
|
|
inside the archive: |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
file://path/file.ext/subpath |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub new { |
68
|
1
|
|
|
1
|
1
|
1989
|
my ($class, $root, $options) = @_; |
69
|
1
|
50
|
|
|
|
9
|
my $uri = URI->new($root) or return; |
70
|
1
|
|
|
|
|
4866
|
$options->{uri} = $uri; |
71
|
1
|
|
|
|
|
3
|
my $fsclass = $options->{vfs}; |
72
|
1
|
50
|
33
|
|
|
7
|
if (!$uri->scheme() || $uri->scheme() eq 'ext' || !$uri->authority) { |
|
|
0
|
33
|
|
|
|
|
73
|
1
|
|
|
|
|
44
|
my @part = split(/\/+/, $uri->path()); |
74
|
1
|
|
50
|
|
|
22
|
my $path = (shift(@part) || ''); |
75
|
1
|
|
100
|
|
|
8
|
while(!($path && -f $path) && @part) { |
|
|
|
66
|
|
|
|
|
76
|
2
|
|
|
|
|
56
|
$path .= '/' . shift(@part); |
77
|
|
|
|
|
|
|
} |
78
|
1
|
50
|
|
|
|
5
|
if (!$fsclass) { |
79
|
0
|
0
|
0
|
|
|
0
|
if (($uri->scheme() || '') eq 'ext' || (!$uri->scheme() && !$uri->authority)) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
$path =~ m/\.([^\.]*)$/; |
81
|
0
|
0
|
|
|
|
0
|
$fsclass = $1 if ($1); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
1
|
50
|
|
|
|
3
|
if (@part) { |
85
|
1
|
|
|
|
|
3
|
$options->{rootfile} = $path; |
86
|
1
|
|
|
|
|
5
|
$options->{subpath} = '/' . join('/', @part); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} elsif(!$fsclass) { |
89
|
0
|
|
|
|
|
0
|
$fsclass = $uri->scheme(); |
90
|
|
|
|
|
|
|
} |
91
|
1
|
|
50
|
|
|
5
|
$fsclass = ucfirst(lc($fsclass || 'file')); |
92
|
1
|
|
|
|
|
3
|
my $fullclass = "VFSsimple::Drv::$fsclass"; |
93
|
1
|
|
|
1
|
|
74
|
eval "use $fullclass"; |
|
1
|
|
|
|
|
375
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# TODO the use can failed if package is load inline see t/02-instanciate.t |
95
|
|
|
|
|
|
|
# if ($@) { |
96
|
|
|
|
|
|
|
# warn "Can't load $fullclass\n"; |
97
|
|
|
|
|
|
|
# return; |
98
|
|
|
|
|
|
|
# } |
99
|
2
|
|
|
2
|
|
14
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
632
|
|
100
|
1
|
|
|
|
|
11
|
return $fullclass->new($root, $options); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 root |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Return the root of the VFS. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 error |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Return the last error. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub error { |
114
|
0
|
|
|
0
|
1
|
0
|
$_[0]->{_error} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 get($src) |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Fetch the file if necessary, and return the local location |
120
|
|
|
|
|
|
|
where it has been copied. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub get { |
125
|
0
|
|
|
0
|
1
|
0
|
my ($self, $src) = @_; |
126
|
0
|
|
|
|
|
0
|
return $self->drv_get($src); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 open($src) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Fetch the file if necessary and return an open file handle |
132
|
|
|
|
|
|
|
on it. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub open { |
137
|
0
|
|
|
0
|
1
|
0
|
my ($self, $src) = @_; |
138
|
0
|
|
|
|
|
0
|
return $self->drv_open($src); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 copy($src, $dest) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Copy $src file from vfs into $dest local file |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub copy { |
148
|
0
|
|
|
0
|
1
|
0
|
my ($self, $src, $dest) = @_; |
149
|
0
|
|
|
|
|
0
|
return $self->drv_copy($src, $dest); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 exists($file) |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Return True if $file exists on the VFS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub exists { |
159
|
0
|
|
|
0
|
1
|
0
|
my ($self, $file) = @_; |
160
|
0
|
|
|
|
|
0
|
return $self->drv_exists($file); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |