line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::File::Role::Extension; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
3647
|
use Mojo::Base -role, -signatures; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
16
|
|
4
|
2
|
|
|
2
|
|
9223
|
use Mojo::Collection 'c'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1114
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
requires 'path'; |
9
|
|
|
|
|
|
|
|
10
|
16
|
|
|
16
|
1
|
2919
|
sub extension ($self) { |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
26
|
|
11
|
16
|
|
|
|
|
27
|
return _basename_parse($self, 1); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
9
|
|
|
9
|
1
|
701
|
sub extension_parts ($self) { |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
11
|
|
15
|
9
|
|
|
|
|
17
|
return c(split /(?=\.)/ => _basename_parse($self, 1)); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
9
|
|
|
9
|
1
|
4592
|
sub moniker ($self) { |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
21
|
|
19
|
9
|
|
|
|
|
21
|
return _basename_parse($self); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
4
|
1
|
1813
|
sub switch_extension ($self, $suffix = '') { |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
12
|
|
23
|
4
|
|
|
|
|
13
|
return $self->sibling(join '' => _basename_parse($self), $suffix); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
38
|
|
|
38
|
|
57
|
sub _basename_parse ($self, $extension = 0) { |
|
38
|
|
|
|
|
57
|
|
|
38
|
|
|
|
|
50
|
|
|
38
|
|
|
|
|
52
|
|
27
|
38
|
|
|
|
|
93
|
my $base = $self->basename; |
28
|
38
|
100
|
|
|
|
1167
|
my $idx = $extension ? 2 : 0; |
29
|
38
|
|
|
|
|
157
|
require File::Basename; |
30
|
38
|
|
|
|
|
864
|
return (File::Basename::fileparse($base, qr/((\.[^\.]+)+)$/))[$idx]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=encoding utf8 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=begin html |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
alt="Travis Build Status" /> |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
alt="Kritika Analysis Status" /> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
alt="Coverage Status" /> |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=end html |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Mojo::File::Role::Extension - Access Mojo::File filename extensions |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$file = Mojo::File->new('/some/path.txt')->with_roles('+Extension'); |
64
|
|
|
|
|
|
|
# .txt |
65
|
|
|
|
|
|
|
$file->extension; |
66
|
|
|
|
|
|
|
# /some/path.csv |
67
|
|
|
|
|
|
|
$file->switch_extension('.csv'); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DESCRIPTION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Add file extension access and modifying behaviour to L. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
The L role adds the following methods to a |
76
|
|
|
|
|
|
|
L once composed. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 extension |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# .txt |
81
|
|
|
|
|
|
|
$file->extension; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Readonly access to the file extension of the file or directory. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 extension_parts |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# ['.tar', '.gz'] |
88
|
|
|
|
|
|
|
$file->extension_parts; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Readonly access to the file extension(s) of the file or directory. The parts are |
91
|
|
|
|
|
|
|
returned as a L of strings. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 moniker |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# path |
96
|
|
|
|
|
|
|
$file->moniker; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Readonly access to the short name of the file, i.e. prior to the |
99
|
|
|
|
|
|
|
L"extension">. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 switch_extension |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# /some/path.csv |
104
|
|
|
|
|
|
|
$file->switch_extension('.csv'); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Change the extension of the L, retaining the rest of the path and |
107
|
|
|
|
|
|
|
return a new L object. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify it under |
112
|
|
|
|
|
|
|
the same terms as Perl itself. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHORS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Roy Storey - |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |