line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Util::Path; |
2
|
|
|
|
|
|
|
|
3
|
121
|
|
|
121
|
|
932
|
use Catmandu::Sane; |
|
121
|
|
|
|
|
293
|
|
|
121
|
|
|
|
|
801
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
121
|
|
|
121
|
|
1451
|
use Catmandu::Util qw(is_value is_string require_package); |
|
121
|
|
|
|
|
335
|
|
|
121
|
|
|
|
|
7559
|
|
8
|
121
|
|
|
121
|
|
782
|
use namespace::clean; |
|
121
|
|
|
|
|
380
|
|
|
121
|
|
|
|
|
882
|
|
9
|
121
|
|
|
121
|
|
35789
|
use Exporter qw(import); |
|
121
|
|
|
|
|
322
|
|
|
121
|
|
|
|
|
35879
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
12
|
|
|
|
|
|
|
looks_like_path |
13
|
|
|
|
|
|
|
as_path |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => \@EXPORT_OK,); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub looks_like_path { # TODO only recognizes Catmandu::Path::simple |
19
|
4
|
|
|
4
|
1
|
8
|
my ($path) = @_; |
20
|
4
|
100
|
66
|
|
|
35
|
is_string($path) && $path =~ /^\$[\.\/]/ ? 1 : 0; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub as_path { |
24
|
591
|
|
|
591
|
1
|
1496
|
my ($path, $path_type) = @_; |
25
|
591
|
50
|
|
|
|
2518
|
if (is_value($path)) { |
26
|
591
|
|
50
|
|
|
3036
|
$path_type //= 'simple'; |
27
|
591
|
|
|
|
|
1013
|
state $class_cache = {}; |
28
|
591
|
|
66
|
|
|
2559
|
my $class = $class_cache->{$path_type} |
29
|
|
|
|
|
|
|
||= require_package($path_type, 'Catmandu::Path'); |
30
|
591
|
|
|
|
|
9542
|
$class->new(path => $path); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
0
|
|
|
|
|
|
$path; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=pod |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Catmandu::Util::Path - Path related utility functions |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 FUNCTIONS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=over 4 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item looks_like_path($str) |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns 1 if the given string is a path, 0 otherwise. Only recognizes |
54
|
|
|
|
|
|
|
L<Catmandu::Path::simple> paths prefixed with a dollar sign at the moment. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
looks_like_path("$.foo.bar.$append") |
57
|
|
|
|
|
|
|
# => 1 |
58
|
|
|
|
|
|
|
looks_like_path("waffles") |
59
|
|
|
|
|
|
|
# => 0 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item as_path($str, $type) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Helper function that returns a L<Catmandu::Path> instance for the given path |
64
|
|
|
|
|
|
|
string. The optional C<$type> argument gives preliminary support for |
65
|
|
|
|
|
|
|
alternative path implementations and defaults to 'simple'. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
as_path("$.foo.bar.$append") |
68
|
|
|
|
|
|
|
# is equivalent to |
69
|
|
|
|
|
|
|
Catmandu::Path::simple->new(path => "$.foo.bar.$append"); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=back |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |