Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ->has_encoding & ->is_encoded_content to files #263

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Revision history for {{$dist->name}}

{{$NEXT}}
- load DateTime lazily
- add ->has_encoding & ->is_encoded_content to files
(thanks, Christopher J. Madsen)

5.019 2014-05-20 21:11:47-04:00 America/New_York
- remove a very brief-lived attempt to double-decode
Expand Down
4 changes: 4 additions & 0 deletions lib/Dist/Zilla/File/FromCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ has code_return_type => (
default => 'text',
);

sub is_encoded_content { shift->code_return_type eq 'bytes' }

=attr encoding

=cut
Expand All @@ -51,6 +53,8 @@ has encoding => (
builder => "_build_encoding",
);

sub has_encoding { 1 } # You can't change the encoding of a FromCode file

sub _build_encoding {
my ($self) = @_;
return $self->code_return_type eq 'text' ? 'UTF-8' : 'bytes';
Expand Down
2 changes: 2 additions & 0 deletions lib/Dist/Zilla/Role/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ has mode => (
);

requires 'encoding';
requires 'has_encoding';
requires 'content';
requires 'encoded_content';
requires 'is_encoded_content';

=method is_bytes

Expand Down
4 changes: 4 additions & 0 deletions lib/Dist/Zilla/Role/MutableFile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ Default is 'UTF-8'. Can only be set once.
with 'Dist::Zilla::Role::File';

sub encoding;
sub has_encoding;

has encoding => (
is => 'rw',
isa => 'Str',
lazy => 1,
default => 'UTF-8',
predicate => 'has_encoding',
traits => [ qw(SetOnce) ],
);

Expand Down Expand Up @@ -100,6 +102,8 @@ has _content_source => (
builder => '_build_content_source',
);

sub is_encoded_content { shift->_content_source eq 'encoded_content' }

sub _update_by {
my ($self, $attr, $from) = @_;
$self->_content_source($attr);
Expand Down