| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
114015
|
use strict; |
|
|
2
|
|
|
|
|
22
|
|
|
|
2
|
|
|
|
|
52
|
|
|
2
|
2
|
|
|
2
|
|
9
|
use warnings; # stupid CPANTS! |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
119
|
|
|
3
|
|
|
|
|
|
|
package Path::Resolver 3.100455; |
|
4
|
|
|
|
|
|
|
# ABSTRACT: go from "file" names to things |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
|
7
|
|
|
|
|
|
|
#pod |
|
8
|
|
|
|
|
|
|
#pod Path::Resolver is a set of libraries for resolving virtual file paths into |
|
9
|
|
|
|
|
|
|
#pod entities that may be found at those paths. Here's a trivial example: |
|
10
|
|
|
|
|
|
|
#pod |
|
11
|
|
|
|
|
|
|
#pod use Path::Resolver::Resolver::FileSystem; |
|
12
|
|
|
|
|
|
|
#pod |
|
13
|
|
|
|
|
|
|
#pod # Create a resolver that looks at the filesystem, starting in /etc |
|
14
|
|
|
|
|
|
|
#pod my $fs = Path::Resolver::Resolver::FileSystem->new({ root => '/etc' }); |
|
15
|
|
|
|
|
|
|
#pod |
|
16
|
|
|
|
|
|
|
#pod my $file = $fs->entity_at('/postfix/main.cf'); |
|
17
|
|
|
|
|
|
|
#pod |
|
18
|
|
|
|
|
|
|
#pod Assuming it exists, this will return an object representing the file |
|
19
|
|
|
|
|
|
|
#pod F</etc/postfix/main.cf>. Using the code above, C<$file> would be a |
|
20
|
|
|
|
|
|
|
#pod C<Path::Resolver::SimpleEntity> object, which has a C<content> method. We |
|
21
|
|
|
|
|
|
|
#pod could print the contents of the file to screen like this: |
|
22
|
|
|
|
|
|
|
#pod |
|
23
|
|
|
|
|
|
|
#pod print $file->content; |
|
24
|
|
|
|
|
|
|
#pod |
|
25
|
|
|
|
|
|
|
#pod =head1 WHAT'S THE POINT? |
|
26
|
|
|
|
|
|
|
#pod |
|
27
|
|
|
|
|
|
|
#pod Path::Resolver lets you use a simple, familiar notation for accessing all kinds |
|
28
|
|
|
|
|
|
|
#pod of hierarchical data. It's also distributed with resolvers that act as |
|
29
|
|
|
|
|
|
|
#pod multiplexers for other resolvers. Since all resolvers share one mechanism for |
|
30
|
|
|
|
|
|
|
#pod addressing content, they can easily be mixed and matched. Since resolvers know |
|
31
|
|
|
|
|
|
|
#pod what kind of object they'll return, and can be fitted with translators, it's |
|
32
|
|
|
|
|
|
|
#pod easy to ensure that all your multiplexed resolvers will resolve names to the |
|
33
|
|
|
|
|
|
|
#pod same kind of object. |
|
34
|
|
|
|
|
|
|
#pod |
|
35
|
|
|
|
|
|
|
#pod For example, we could overlay two search paths like this: |
|
36
|
|
|
|
|
|
|
#pod |
|
37
|
|
|
|
|
|
|
#pod my $resolver = Path::Resolver::Resolver::Mux::Ordered->new({ |
|
38
|
|
|
|
|
|
|
#pod resolvers => [ |
|
39
|
|
|
|
|
|
|
#pod Path::Resolver::Resolver::FileSystem->new({ root => './config' }), |
|
40
|
|
|
|
|
|
|
#pod Path::Resolver::Resolver::Archive::Tar->new({ archive => 'config.tgz' }), |
|
41
|
|
|
|
|
|
|
#pod ], |
|
42
|
|
|
|
|
|
|
#pod }); |
|
43
|
|
|
|
|
|
|
#pod |
|
44
|
|
|
|
|
|
|
#pod $resolver->entity_at('/foo/bar.txt'); |
|
45
|
|
|
|
|
|
|
#pod |
|
46
|
|
|
|
|
|
|
#pod This will return an entity representing F<./config/foo/bar.txt> if it exists. |
|
47
|
|
|
|
|
|
|
#pod If it doesn't, it will look for F<foo/bar.txt> in the contents of the archive. |
|
48
|
|
|
|
|
|
|
#pod If that's found, an entity will be returned. Finally, if neither is found, it |
|
49
|
|
|
|
|
|
|
#pod will return false. |
|
50
|
|
|
|
|
|
|
#pod |
|
51
|
|
|
|
|
|
|
#pod Alternately, you could multiplex based on path: |
|
52
|
|
|
|
|
|
|
#pod |
|
53
|
|
|
|
|
|
|
#pod my $resolver = Path::Resolver::Resolver::Mux::Prefix->new({ |
|
54
|
|
|
|
|
|
|
#pod config => Path::Resolver::Resolver::FileSystem->new({ |
|
55
|
|
|
|
|
|
|
#pod root => '/etc/my-app', |
|
56
|
|
|
|
|
|
|
#pod }), |
|
57
|
|
|
|
|
|
|
#pod |
|
58
|
|
|
|
|
|
|
#pod template => Path::Resolver::Resolver::Mux::Ordered->new({ |
|
59
|
|
|
|
|
|
|
#pod Path::Resolver::Resolver::DistDir->new({ module => 'MyApp' }), |
|
60
|
|
|
|
|
|
|
#pod Path::Resolver::Resolver::DataSection->new({ module => 'My::Framework' }), |
|
61
|
|
|
|
|
|
|
#pod }), |
|
62
|
|
|
|
|
|
|
#pod }); |
|
63
|
|
|
|
|
|
|
#pod |
|
64
|
|
|
|
|
|
|
#pod The path F</config/main.cf> would be looked for on disk as |
|
65
|
|
|
|
|
|
|
#pod F</etc/my-app/main.cf>. The path F</template/main.html> would be looked for |
|
66
|
|
|
|
|
|
|
#pod first as F<main.html> in the sharedir for MyApp and failing that in the DATA |
|
67
|
|
|
|
|
|
|
#pod section of My::Framework. |
|
68
|
|
|
|
|
|
|
#pod |
|
69
|
|
|
|
|
|
|
#pod =head1 WHERE DO I GO NEXT? |
|
70
|
|
|
|
|
|
|
#pod |
|
71
|
|
|
|
|
|
|
#pod If you want to read about how to write a resolver, look at |
|
72
|
|
|
|
|
|
|
#pod L<Path::Resolver::Role::Resolver|Path::Resolver::Role::Resolver>. |
|
73
|
|
|
|
|
|
|
#pod |
|
74
|
|
|
|
|
|
|
#pod If you want to read about the interfaces to the existing resolvers look at |
|
75
|
|
|
|
|
|
|
#pod their documentation: |
|
76
|
|
|
|
|
|
|
#pod |
|
77
|
|
|
|
|
|
|
#pod =over |
|
78
|
|
|
|
|
|
|
#pod |
|
79
|
|
|
|
|
|
|
#pod =item * L<Path::Resolver::Resolver::AnyDist> |
|
80
|
|
|
|
|
|
|
#pod |
|
81
|
|
|
|
|
|
|
#pod =item * L<Path::Resolver::Resolver::Archive::Tar> |
|
82
|
|
|
|
|
|
|
#pod |
|
83
|
|
|
|
|
|
|
#pod =item * L<Path::Resolver::Resolver::DataSection> |
|
84
|
|
|
|
|
|
|
#pod |
|
85
|
|
|
|
|
|
|
#pod =item * L<Path::Resolver::Resolver::DistDir> |
|
86
|
|
|
|
|
|
|
#pod |
|
87
|
|
|
|
|
|
|
#pod =item * L<Path::Resolver::Resolver::FileSystem> |
|
88
|
|
|
|
|
|
|
#pod |
|
89
|
|
|
|
|
|
|
#pod =item * L<Path::Resolver::Resolver::Hash> |
|
90
|
|
|
|
|
|
|
#pod |
|
91
|
|
|
|
|
|
|
#pod =item * L<Path::Resolver::Resolver::Mux::Ordered> |
|
92
|
|
|
|
|
|
|
#pod |
|
93
|
|
|
|
|
|
|
#pod =item * L<Path::Resolver::Resolver::Mux::Prefix> |
|
94
|
|
|
|
|
|
|
#pod |
|
95
|
|
|
|
|
|
|
#pod =back |
|
96
|
|
|
|
|
|
|
#pod |
|
97
|
|
|
|
|
|
|
#pod =cut |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=pod |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=encoding UTF-8 |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 NAME |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Path::Resolver - go from "file" names to things |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 VERSION |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
version 3.100455 |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Path::Resolver is a set of libraries for resolving virtual file paths into |
|
118
|
|
|
|
|
|
|
entities that may be found at those paths. Here's a trivial example: |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
use Path::Resolver::Resolver::FileSystem; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Create a resolver that looks at the filesystem, starting in /etc |
|
123
|
|
|
|
|
|
|
my $fs = Path::Resolver::Resolver::FileSystem->new({ root => '/etc' }); |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $file = $fs->entity_at('/postfix/main.cf'); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Assuming it exists, this will return an object representing the file |
|
128
|
|
|
|
|
|
|
F</etc/postfix/main.cf>. Using the code above, C<$file> would be a |
|
129
|
|
|
|
|
|
|
C<Path::Resolver::SimpleEntity> object, which has a C<content> method. We |
|
130
|
|
|
|
|
|
|
could print the contents of the file to screen like this: |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
print $file->content; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 PERL VERSION |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This library should run on perls released even a long time ago. It should work |
|
137
|
|
|
|
|
|
|
on any version of perl released in the last five years. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Although it may work on older versions of perl, no guarantee is made that the |
|
140
|
|
|
|
|
|
|
minimum required version will not be increased. The version may be increased |
|
141
|
|
|
|
|
|
|
for any reason, and there is no promise that patches will be accepted to lower |
|
142
|
|
|
|
|
|
|
the minimum required perl. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 WHAT'S THE POINT? |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Path::Resolver lets you use a simple, familiar notation for accessing all kinds |
|
147
|
|
|
|
|
|
|
of hierarchical data. It's also distributed with resolvers that act as |
|
148
|
|
|
|
|
|
|
multiplexers for other resolvers. Since all resolvers share one mechanism for |
|
149
|
|
|
|
|
|
|
addressing content, they can easily be mixed and matched. Since resolvers know |
|
150
|
|
|
|
|
|
|
what kind of object they'll return, and can be fitted with translators, it's |
|
151
|
|
|
|
|
|
|
easy to ensure that all your multiplexed resolvers will resolve names to the |
|
152
|
|
|
|
|
|
|
same kind of object. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
For example, we could overlay two search paths like this: |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $resolver = Path::Resolver::Resolver::Mux::Ordered->new({ |
|
157
|
|
|
|
|
|
|
resolvers => [ |
|
158
|
|
|
|
|
|
|
Path::Resolver::Resolver::FileSystem->new({ root => './config' }), |
|
159
|
|
|
|
|
|
|
Path::Resolver::Resolver::Archive::Tar->new({ archive => 'config.tgz' }), |
|
160
|
|
|
|
|
|
|
], |
|
161
|
|
|
|
|
|
|
}); |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$resolver->entity_at('/foo/bar.txt'); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This will return an entity representing F<./config/foo/bar.txt> if it exists. |
|
166
|
|
|
|
|
|
|
If it doesn't, it will look for F<foo/bar.txt> in the contents of the archive. |
|
167
|
|
|
|
|
|
|
If that's found, an entity will be returned. Finally, if neither is found, it |
|
168
|
|
|
|
|
|
|
will return false. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Alternately, you could multiplex based on path: |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
my $resolver = Path::Resolver::Resolver::Mux::Prefix->new({ |
|
173
|
|
|
|
|
|
|
config => Path::Resolver::Resolver::FileSystem->new({ |
|
174
|
|
|
|
|
|
|
root => '/etc/my-app', |
|
175
|
|
|
|
|
|
|
}), |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
template => Path::Resolver::Resolver::Mux::Ordered->new({ |
|
178
|
|
|
|
|
|
|
Path::Resolver::Resolver::DistDir->new({ module => 'MyApp' }), |
|
179
|
|
|
|
|
|
|
Path::Resolver::Resolver::DataSection->new({ module => 'My::Framework' }), |
|
180
|
|
|
|
|
|
|
}), |
|
181
|
|
|
|
|
|
|
}); |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
The path F</config/main.cf> would be looked for on disk as |
|
184
|
|
|
|
|
|
|
F</etc/my-app/main.cf>. The path F</template/main.html> would be looked for |
|
185
|
|
|
|
|
|
|
first as F<main.html> in the sharedir for MyApp and failing that in the DATA |
|
186
|
|
|
|
|
|
|
section of My::Framework. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 WHERE DO I GO NEXT? |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
If you want to read about how to write a resolver, look at |
|
191
|
|
|
|
|
|
|
L<Path::Resolver::Role::Resolver|Path::Resolver::Role::Resolver>. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
If you want to read about the interfaces to the existing resolvers look at |
|
194
|
|
|
|
|
|
|
their documentation: |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=over |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * L<Path::Resolver::Resolver::AnyDist> |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * L<Path::Resolver::Resolver::Archive::Tar> |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * L<Path::Resolver::Resolver::DataSection> |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * L<Path::Resolver::Resolver::DistDir> |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * L<Path::Resolver::Resolver::FileSystem> |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * L<Path::Resolver::Resolver::Hash> |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * L<Path::Resolver::Resolver::Mux::Ordered> |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item * L<Path::Resolver::Resolver::Mux::Prefix> |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=back |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 AUTHOR |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Ricardo Signes <cpan@semiotic.systems> |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=for stopwords Florian Ragwitz Ricardo Signes |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=over 4 |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item * |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Ricardo Signes <rjbs@semiotic.systems> |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=back |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
This software is copyright (c) 2022 by Ricardo Signes. |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
241
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |