diff --git a/Changes b/Changes index b6c1c3da5..341500a54 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/lib/Dist/Zilla/File/FromCode.pm b/lib/Dist/Zilla/File/FromCode.pm index 009af8ca5..2f9aa590a 100644 --- a/lib/Dist/Zilla/File/FromCode.pm +++ b/lib/Dist/Zilla/File/FromCode.pm @@ -38,6 +38,8 @@ has code_return_type => ( default => 'text', ); +sub is_encoded_content { shift->code_return_type eq 'bytes' } + =attr encoding =cut @@ -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'; diff --git a/lib/Dist/Zilla/Role/File.pm b/lib/Dist/Zilla/Role/File.pm index f8228fa5a..dd93fab65 100644 --- a/lib/Dist/Zilla/Role/File.pm +++ b/lib/Dist/Zilla/Role/File.pm @@ -60,8 +60,10 @@ has mode => ( ); requires 'encoding'; +requires 'has_encoding'; requires 'content'; requires 'encoded_content'; +requires 'is_encoded_content'; =method is_bytes diff --git a/lib/Dist/Zilla/Role/MutableFile.pm b/lib/Dist/Zilla/Role/MutableFile.pm index 8b22c1da1..0d1e54cd0 100644 --- a/lib/Dist/Zilla/Role/MutableFile.pm +++ b/lib/Dist/Zilla/Role/MutableFile.pm @@ -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) ], ); @@ -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);