line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Path::File::Win32; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.92'; # VERSION |
4
|
|
|
|
|
|
|
# ABSTRACT: C:\Windows\file\path\support |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
############################################################################# |
7
|
|
|
|
|
|
|
# Modules |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
2059
|
use Moo; |
|
1
|
|
|
|
|
12421
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
2549
|
use sanity; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
431163
|
use Types::Standard qw(StrMatch); |
|
1
|
|
|
|
|
112428
|
|
|
1
|
|
|
|
|
14
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
878
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
15
|
1
|
|
|
1
|
|
216
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
680
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
############################################################################# |
18
|
|
|
|
|
|
|
# Attributes |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has volume => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => StrMatch[ qr/^[A-Za-z]?$/ ], |
23
|
|
|
|
|
|
|
default => sub { '' }, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
############################################################################# |
27
|
|
|
|
|
|
|
# Required Methods |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
with 'Parse::Path::Role::Path'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _build_blueprint { { |
32
|
22
|
|
|
22
|
|
2884
|
hash_step_regexp => qr{ |
33
|
|
|
|
|
|
|
# Illegal characters: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx |
34
|
|
|
|
|
|
|
(?<key>[^\x00-\x1F<>:"/\\|?*]*) |
35
|
|
|
|
|
|
|
}x, |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
array_step_regexp => qr/\Z.\A/, # no-op; arrays not supported |
38
|
|
|
|
|
|
|
delimiter_regexp => qr{\\+}, # + to capture repetitive slashes, like foo\\\\\bar |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# no support for escapes |
41
|
|
|
|
|
|
|
unescape_translation => [], |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
pos_translation => [ |
44
|
|
|
|
|
|
|
[qr{^\\+$}, 0], |
45
|
|
|
|
|
|
|
[qr{^\.\.\\*$}, 'X-1'], |
46
|
|
|
|
|
|
|
[qr{^\.\\*$}, 'X-0'], |
47
|
|
|
|
|
|
|
[qr{.?}, 'X+1'], |
48
|
|
|
|
|
|
|
], |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
delimiter_placement => { |
51
|
|
|
|
|
|
|
'0R' => "\\", |
52
|
|
|
|
|
|
|
HH => "\\", |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
array_key_sprintf => '', |
56
|
|
|
|
|
|
|
hash_key_stringification => [ |
57
|
|
|
|
|
|
|
[qr/.?/, '%s'], |
58
|
|
|
|
|
|
|
], |
59
|
|
|
|
|
|
|
} } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
############################################################################# |
62
|
|
|
|
|
|
|
# Modified Methods |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Remove volume to the path |
65
|
|
|
|
|
|
|
around path_str2array => sub { |
66
|
|
|
|
|
|
|
my ($orig, $self, $path) = (shift, shift, shift); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$self->volume($1) if ($path =~ s/^([A-Za-z])\://); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return $self->$orig($path, @_); |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Uppercase volume on normalize |
74
|
|
|
|
|
|
|
around _normalize => sub { |
75
|
|
|
|
|
|
|
my ($orig, $self) = (shift, shift); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$self->volume(uc $self->volume); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return $self->$orig(@_); |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Add volume to the path |
83
|
|
|
|
|
|
|
around as_string => sub { |
84
|
|
|
|
|
|
|
my ($orig, $self) = (shift, shift); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $path_str = $self->$orig(@_); |
87
|
|
|
|
|
|
|
my $V = $self->volume; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return ($V ? "$V:" : '').$path_str; |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
42; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=pod |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=encoding utf-8 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 NAME |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Parse::Path::File::Win32 - C:\Windows\file\path\support |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SYNOPSIS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
use v5.10; |
107
|
|
|
|
|
|
|
use Parse::Path; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $path = Parse::Path->new( |
110
|
|
|
|
|
|
|
path => 'C:\WINDOWS\SYSTEM32', |
111
|
|
|
|
|
|
|
style => 'File::Win32', |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
say $path->as_string; |
115
|
|
|
|
|
|
|
$path->push($path, 'DRIVERS'); |
116
|
|
|
|
|
|
|
say $path->as_string; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$path->volume('D'); |
119
|
|
|
|
|
|
|
say $path->as_string; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 DESCRIPTION |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is a file-based path style for Windows paths. Some examples: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
C:\WINDOWS |
126
|
|
|
|
|
|
|
c:\windows |
127
|
|
|
|
|
|
|
\Users |
128
|
|
|
|
|
|
|
C:foo\bar.txt |
129
|
|
|
|
|
|
|
..\..\..\.\aaa\.\\\\\\bbb\ccc\..\ddd |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Arrays are, of course, not supported. Neither is quoting, as that is a product of the shell, not the path itself. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Absolute paths will contain a blank first step, a la L<Path::Class>. Though, it is recommended to use |
134
|
|
|
|
|
|
|
L<is_absolute|Parse::Path/is_absolute> for checking for path relativity. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 EXTRA ATTRIBUTES |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 volume |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $volume = $path->volume; |
141
|
|
|
|
|
|
|
$path->volume('Z'); |
142
|
|
|
|
|
|
|
$path->volume(''); # removes the volume |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Returns or sets the volume. This must be a single letter, or a blank string to remove it. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Volumes are automatically extracted and put into this attribute when passed as a path string. If transformed back into a string, it |
147
|
|
|
|
|
|
|
will show the volume again. Normalization will capitalize the volume, as there is no difference between C<<< C: >>> and C<<< c: >>>. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 CAVEATS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Though Windows isn't case-sensitive, it does support upper and lowercase letters. Thus, there is no logic to force case on the |
156
|
|
|
|
|
|
|
paths (except for volume), and is left as an exercise to the user. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
UNC paths are not supported. This would be a different path style, anyway. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AVAILABILITY |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The project homepage is L<https://github.com/SineSwiper/Parse-Path/wiki>. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
The latest version of this module is available from the Comprehensive Perl |
169
|
|
|
|
|
|
|
Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN |
170
|
|
|
|
|
|
|
site near you, or see L<https://metacpan.org/module/Parse::Path/>. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Brendan Byrd <bbyrd@cpan.org> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This software is Copyright (c) 2013 by Brendan Byrd. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This is free software, licensed under: |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |