| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dist::Zilla::Role::File 6.030; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: something that can act like a file |
|
3
|
|
|
|
|
|
|
|
|
4
|
52
|
|
|
52
|
|
36437
|
use Moose::Role; |
|
|
52
|
|
|
|
|
5232
|
|
|
|
52
|
|
|
|
|
381
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
52
|
|
|
52
|
|
271543
|
use Dist::Zilla::Pragmas; |
|
|
52
|
|
|
|
|
146
|
|
|
|
52
|
|
|
|
|
418
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
52
|
|
|
52
|
|
1836
|
use Dist::Zilla::Types qw(_Filename); |
|
|
52
|
|
|
|
|
183
|
|
|
|
52
|
|
|
|
|
649
|
|
|
9
|
52
|
|
|
52
|
|
123537
|
use Moose::Util::TypeConstraints; |
|
|
52
|
|
|
|
|
244
|
|
|
|
52
|
|
|
|
|
479
|
|
|
10
|
52
|
|
|
52
|
|
114729
|
use Try::Tiny; |
|
|
52
|
|
|
|
|
153
|
|
|
|
52
|
|
|
|
|
3879
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
52
|
|
|
52
|
|
405
|
use namespace::autoclean; |
|
|
52
|
|
|
|
|
187
|
|
|
|
52
|
|
|
|
|
429
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::StubBuild'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
|
17
|
|
|
|
|
|
|
#pod |
|
18
|
|
|
|
|
|
|
#pod This role describes a file that may be written into the shipped distribution. |
|
19
|
|
|
|
|
|
|
#pod |
|
20
|
|
|
|
|
|
|
#pod =attr name |
|
21
|
|
|
|
|
|
|
#pod |
|
22
|
|
|
|
|
|
|
#pod This is the name of the file to be written out. |
|
23
|
|
|
|
|
|
|
#pod |
|
24
|
|
|
|
|
|
|
#pod =cut |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has name => ( |
|
27
|
|
|
|
|
|
|
is => 'rw', |
|
28
|
|
|
|
|
|
|
isa => _Filename, |
|
29
|
|
|
|
|
|
|
required => 1, |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#pod =attr added_by |
|
33
|
|
|
|
|
|
|
#pod |
|
34
|
|
|
|
|
|
|
#pod This is a list of strings describing when and why the file was added |
|
35
|
|
|
|
|
|
|
#pod to the distribution and when it was updated (its content, filename, or other attributes). It will |
|
36
|
|
|
|
|
|
|
#pod generally be updated by a plugin implementing the |
|
37
|
|
|
|
|
|
|
#pod L<FileMunger|Dist::Zilla::Role::FileMunger> role. Its accessor will return |
|
38
|
|
|
|
|
|
|
#pod the list of strings, concatenated with C<'; '>. |
|
39
|
|
|
|
|
|
|
#pod |
|
40
|
|
|
|
|
|
|
#pod =cut |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has added_by => ( |
|
43
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
|
44
|
|
|
|
|
|
|
lazy => 1, |
|
45
|
|
|
|
|
|
|
default => sub { [] }, |
|
46
|
|
|
|
|
|
|
traits => ['Array'], |
|
47
|
|
|
|
|
|
|
init_arg => undef, |
|
48
|
|
|
|
|
|
|
handles => { |
|
49
|
|
|
|
|
|
|
_push_added_by => 'push', |
|
50
|
|
|
|
|
|
|
added_by => [ join => '; ' ], |
|
51
|
|
|
|
|
|
|
}, |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
around name => sub { |
|
55
|
|
|
|
|
|
|
my $orig = shift; |
|
56
|
|
|
|
|
|
|
my $self = shift; |
|
57
|
|
|
|
|
|
|
if (@_) { |
|
58
|
|
|
|
|
|
|
my ($pkg, $line) = $self->_caller_of('name'); |
|
59
|
|
|
|
|
|
|
$self->_push_added_by(sprintf("filename set by %s (%s line %s)", $self->_caller_plugin_name, $pkg, $line)); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
return $self->$orig(@_); |
|
62
|
|
|
|
|
|
|
}; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _caller_of { |
|
65
|
800
|
|
|
800
|
|
2103
|
my ($self, $function) = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
800
|
|
|
|
|
2519
|
for (my $level = 1; $level < 50; ++$level) |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
2138
|
|
|
|
|
17425
|
my @frame = caller($level); |
|
70
|
2138
|
50
|
|
|
|
5268
|
last if not defined $frame[0]; |
|
71
|
2138
|
100
|
|
|
|
20822
|
return ( (caller($level))[0,2] ) if $frame[3] =~ m/::${function}$/; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
0
|
|
|
|
|
0
|
return 'unknown', '0'; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _caller_plugin_name { |
|
77
|
800
|
|
|
800
|
|
1501
|
my $self = shift; |
|
78
|
|
|
|
|
|
|
|
|
79
|
800
|
|
|
|
|
2315
|
for (my $level = 1; $level < 50; ++$level) |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
2178
|
|
|
|
|
10141
|
my @frame = caller($level); |
|
82
|
2178
|
100
|
|
|
|
5081
|
last if not defined $frame[0]; |
|
83
|
2174
|
100
|
|
|
|
43458
|
return $1 if $frame[0] =~ m/^Dist::Zilla::Plugin::(.+)$/; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
4
|
|
|
|
|
186
|
return 'unknown'; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#pod =attr mode |
|
89
|
|
|
|
|
|
|
#pod |
|
90
|
|
|
|
|
|
|
#pod This is the mode with which the file should be written out. It's an integer |
|
91
|
|
|
|
|
|
|
#pod with the usual C<chmod> semantics. It defaults to 0644. |
|
92
|
|
|
|
|
|
|
#pod |
|
93
|
|
|
|
|
|
|
#pod =cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $safe_file_mode = subtype( |
|
96
|
|
|
|
|
|
|
as 'Int', |
|
97
|
|
|
|
|
|
|
where { not( $_ & 0002) }, |
|
98
|
|
|
|
|
|
|
message { "file mode would be world-writeable" } |
|
99
|
|
|
|
|
|
|
); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
has mode => ( |
|
102
|
|
|
|
|
|
|
is => 'rw', |
|
103
|
|
|
|
|
|
|
isa => $safe_file_mode, |
|
104
|
|
|
|
|
|
|
default => 0644, |
|
105
|
|
|
|
|
|
|
); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
requires 'encoding'; |
|
108
|
|
|
|
|
|
|
requires 'content'; |
|
109
|
|
|
|
|
|
|
requires 'encoded_content'; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#pod =method is_bytes |
|
112
|
|
|
|
|
|
|
#pod |
|
113
|
|
|
|
|
|
|
#pod Returns true if the C<encoding> is bytes. When true, accessing |
|
114
|
|
|
|
|
|
|
#pod C<content> will be an error. |
|
115
|
|
|
|
|
|
|
#pod |
|
116
|
|
|
|
|
|
|
#pod =cut |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub is_bytes { |
|
119
|
625
|
|
|
625
|
1
|
1425
|
my ($self) = @_; |
|
120
|
625
|
|
|
|
|
18649
|
return $self->encoding eq 'bytes'; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _encode { |
|
124
|
177
|
|
|
177
|
|
674
|
my ($self, $text) = @_; |
|
125
|
177
|
|
|
|
|
5579
|
my $enc = $self->encoding; |
|
126
|
177
|
50
|
|
|
|
698
|
if ( $self->is_bytes ) { |
|
127
|
0
|
|
|
|
|
0
|
return $text; # XXX hope you were right that it really was bytes |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
else { |
|
130
|
177
|
|
|
|
|
1148
|
require Encode; |
|
131
|
|
|
|
|
|
|
my $bytes = |
|
132
|
177
|
|
|
177
|
|
10735
|
try { Encode::encode($enc, $text, Encode::FB_CROAK()) } |
|
133
|
177
|
|
|
0
|
|
1920
|
catch { $self->_throw("encode $enc" => $_) }; |
|
|
0
|
|
|
|
|
0
|
|
|
134
|
177
|
|
|
|
|
19811
|
return $bytes; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub _decode { |
|
139
|
177
|
|
|
177
|
|
629
|
my ($self, $bytes) = @_; |
|
140
|
177
|
|
|
|
|
5316
|
my $enc = $self->encoding; |
|
141
|
177
|
100
|
|
|
|
672
|
if ( $self->is_bytes ) { |
|
142
|
3
|
|
|
|
|
32
|
$self->_throw(decode => "Can't decode text from 'bytes' encoding"); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
else { |
|
145
|
174
|
|
|
|
|
1093
|
require Encode; |
|
146
|
|
|
|
|
|
|
my $text = |
|
147
|
174
|
|
|
174
|
|
10721
|
try { Encode::decode($enc, $bytes, Encode::FB_CROAK()) } |
|
148
|
174
|
|
|
0
|
|
1757
|
catch { $self->_throw("decode $enc" => $_) }; |
|
|
0
|
|
|
|
|
0
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# Okay, look, buddy… If you're using a BOM on UTF-8, that's fine. You can |
|
151
|
|
|
|
|
|
|
# use it. You're just not going to get it back. If we don't do this, the |
|
152
|
|
|
|
|
|
|
# sequence of events will be: |
|
153
|
|
|
|
|
|
|
# * read file from UTF-8-BOM file on disk |
|
154
|
|
|
|
|
|
|
# * end up with FEFF as first character of file |
|
155
|
|
|
|
|
|
|
# * pass file content to PPI |
|
156
|
|
|
|
|
|
|
# * PPI blows up |
|
157
|
|
|
|
|
|
|
# |
|
158
|
|
|
|
|
|
|
# I'm not going to try to account for the BOM and add it back. It's awful! |
|
159
|
|
|
|
|
|
|
# |
|
160
|
|
|
|
|
|
|
# Meanwhile, if you're using UTF-16, you can get the BOM handled by picking |
|
161
|
|
|
|
|
|
|
# the right encoding type, I think. -- rjbs, 2016-04-24 |
|
162
|
174
|
100
|
|
|
|
16806
|
$enc =~ /^utf-?8$/i && $text =~ s/\A\x{FEFF}//; |
|
163
|
|
|
|
|
|
|
|
|
164
|
174
|
|
|
|
|
6217
|
return $text; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _throw { |
|
169
|
3
|
|
|
3
|
|
11
|
my ($self, $op, $msg) = @_; |
|
170
|
3
|
|
|
|
|
7
|
my ($name, $added_by) = map {; $self->$_ } qw/name added_by/; |
|
|
6
|
|
|
|
|
163
|
|
|
171
|
3
|
|
|
|
|
1503
|
confess( |
|
172
|
|
|
|
|
|
|
"Could not $op $name; $added_by; error was: $msg; maybe you need the [Encoding] plugin to specify an encoding" |
|
173
|
|
|
|
|
|
|
); |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=pod |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=encoding UTF-8 |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 NAME |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Dist::Zilla::Role::File - something that can act like a file |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 VERSION |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
version 6.030 |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This role describes a file that may be written into the shipped distribution. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 PERL VERSION |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This module should work on any version of perl still receiving updates from |
|
199
|
|
|
|
|
|
|
the Perl 5 Porters. This means it should work on any version of perl released |
|
200
|
|
|
|
|
|
|
in the last two to three years. (That is, if the most recently released |
|
201
|
|
|
|
|
|
|
version is v5.40, then this module should work on both v5.40 and v5.38.) |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Although it may work on older versions of perl, no guarantee is made that the |
|
204
|
|
|
|
|
|
|
minimum required version will not be increased. The version may be increased |
|
205
|
|
|
|
|
|
|
for any reason, and there is no promise that patches will be accepted to lower |
|
206
|
|
|
|
|
|
|
the minimum required perl. |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 name |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This is the name of the file to be written out. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 added_by |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
This is a list of strings describing when and why the file was added |
|
217
|
|
|
|
|
|
|
to the distribution and when it was updated (its content, filename, or other attributes). It will |
|
218
|
|
|
|
|
|
|
generally be updated by a plugin implementing the |
|
219
|
|
|
|
|
|
|
L<FileMunger|Dist::Zilla::Role::FileMunger> role. Its accessor will return |
|
220
|
|
|
|
|
|
|
the list of strings, concatenated with C<'; '>. |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head2 mode |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
This is the mode with which the file should be written out. It's an integer |
|
225
|
|
|
|
|
|
|
with the usual C<chmod> semantics. It defaults to 0644. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 METHODS |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 is_bytes |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Returns true if the C<encoding> is bytes. When true, accessing |
|
232
|
|
|
|
|
|
|
C<content> will be an error. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 AUTHOR |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Ricardo SIGNES 😏 <cpan@semiotic.systems> |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Ricardo SIGNES. |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
243
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |