Dist::Zilla::File::FromCode - a file whose content is (re-)built on demand


Dist-Zilla documentation Contained in the Dist-Zilla distribution.

Index


Code Index:

NAME

Top

Dist::Zilla::File::FromCode - a file whose content is (re-)built on demand

VERSION

Top

version 4.200008

DESCRIPTION

Top

This represents a file whose contents will be generated on demand from a callback or method name.

It has one attribute, code, which may be a method name (string) or a coderef. When the file's content method is called, the code is used to generate the content. This content is not cached. It is recomputed every time the content is requested.

AUTHOR

Top

Ricardo SIGNES <rjbs@cpan.org>

COPYRIGHT AND LICENSE

Top


Dist-Zilla documentation Contained in the Dist-Zilla distribution.

package Dist::Zilla::File::FromCode;
BEGIN {
  $Dist::Zilla::File::FromCode::VERSION = '4.200008';
}
# ABSTRACT: a file whose content is (re-)built on demand
use Moose;


has code => (
  is  => 'rw',
  isa => 'CodeRef|Str',
  required => 1,
);

sub content {
  my ($self) = @_;

  confess "cannot set content of a FromCode file" if @_ > 1;

  my $code = $self->code;
  return $self->$code;
}

with 'Dist::Zilla::Role::File';
__PACKAGE__->meta->make_immutable;
no Moose;
1;

__END__