CPAN-Index-API

 view release on metacpan or  search on metacpan

lib/CPAN/Index/API/Role/Writable.pm  view on Meta::CPAN

package CPAN::Index::API::Role::Writable;

our $VERSION = '0.008';

use strict;
use warnings;

use File::Basename qw(fileparse);
use Path::Class    qw(file dir);
use Path::Tiny     qw(path);
use Text::Template qw(fill_in_string);
use Symbol         qw(qualify_to_ref);
use Scalar::Util   qw(blessed);
use Carp           qw(croak);
use Compress::Zlib qw(gzopen $gzerrno);
use namespace::autoclean;
use Moose::Role;

requires 'default_location';

has tarball_is_default => (
    is         => 'ro',
    isa        => 'Bool',
    lazy_build => 1,
);

has repo_path => (
    is  => 'ro',
    isa => 'Str',
);

has template => (
    is         => 'ro',
    isa        => 'Str',
    required   => 1,
    lazy_build => 1,
);

has content => (
    is         => 'ro',
    isa        => 'Str',
    required   => 1,
    lazy_build => 1,
);

sub _build_template {
    my $self = shift;
    my $data;
    my $error;
    { # catch block
        local $@;
        $error = $@ || 'Error' unless eval { # try block
            my $data_glob = qualify_to_ref("DATA", blessed $self);
            # find the current location before reading
            my $tell = tell($data_glob);
            local $/;
            $data = <$data_glob>;
            # put the location back so we can read again
            # SEEK_SET is 0
            seek($data_glob, $tell, 0);
            1;
        };
    }
    if ($error) {
        warn $error;
        return;
    }
    return $data;
}

sub _build_content {
    my $self = shift;
    my $content = fill_in_string(
        $self->template,
        DELIMITERS => [ '[%', '%]' ],
        HASH       => { self  => \$self },



( run in 0.740 second using v1.01-cache-2.11-cpan-39bf76dae61 )