App-Aphra
view release on metacpan or search on metacpan
lib/App/Aphra.pm view on Meta::CPAN
$config{$_} = $opts{$_} // $defaults{$_};
}
return \%config;
}
has site_vars => (
isa => 'HashRef',
is => 'ro',
lazy_build => 1,
);
sub _build_site_vars {
my $self = shift;
my $site_vars = {};
if (-f 'site.yml') {
$site_vars = LoadFile('site.yml');
}
return $site_vars;
}
has include_path => (
isa => 'ArrayRef',
is => 'ro',
lazy_build => 1,
);
sub _build_include_path {
my $self = shift;
my $include_path;
foreach (qw[source fragments layouts]) {
push @$include_path, $self->config->{$_}
if exists $self->config->{$_};
}
return $include_path;
}
has template => (
isa => 'Template',
is => 'ro',
lazy_build => 1,
);
sub _build_template {
my $self = shift;
my $exts = clone $self->config->{extensions};
delete $exts->{tt};
return Template->new(
ENCODING => 'utf8',
LOAD_TEMPLATES => [
Template::Provider::Pandoc->new(
INCLUDE_PATH => $self->include_path,
EXTENSIONS => $exts,
OUTPUT_FORMAT => $self->config->{output},
STRIP_FRONT_MATTER => 1,
),
],
VARIABLES => {
site => $self->site_vars,
aphra => $self,
},
INCLUDE_PATH => $self->include_path,
OUTPUT_PATH => $self->config->{target},
WRAPPER => $self->config->{wrapper},
);
}
has uri => (
isa => 'URI',
is => 'ro',
lazy_build => 1,
);
sub _build_uri {
my $self = shift;
return URI->new($self->site_vars->{uri}) if $self->site_vars->{uri};
my $host = $self->site_vars->{host} || hostname;
my $protocol = $self->site_vars->{protocol} || 'https';
my $uri = "$protocol://$host";
$uri .= ':' . $self->site_vars->{port} if $self->site_vars->{port};
$uri .= '/';
return URI->new($uri);
}
sub run {
my $self = shift;
$self->config;
@ARGV or die "Must give a command\n";
my $cmd = shift @ARGV;
if (my $method = $self->commands->{$cmd}) {
$self->$method;
} else {
die "$cmd is not a valid command\n";
}
}
sub build {
my $self = shift;
my $src = $self->config->{source};
path($self->config->{target})->remove_tree;
path($self->config->{target})->mkpath;
-e $src or die "Cannot find $src\n";
-d $src or die "$src is not a directory\n";
if ($self->site_vars->{redirects}) {
$self->make_redirects;
}
find({ wanted => $self->_make_do_this, no_chdir => 1 },
$self->config->{source});
}
( run in 1.307 second using v1.01-cache-2.11-cpan-99c4e6809bf )