App-SD
view release on metacpan or search on metacpan
lib/App/SD/CLI/Command/Publish.pm view on Meta::CPAN
# remove trailing dirs according to $depth
if ($depth) {
pop @tmp_dirs while $depth--;
}
$link = '/' . join '/', @tmp_dirs, $link;
}
push @links, $link;
}
return $h->as_HTML, \@links;
}
sub handle_redirect {
my $self = shift;
my $dir = shift;
my $file = shift;
my $new_file = shift;
my $redirected_from = File::Spec->catfile( $dir => $file );
my $redirected_to = File::Spec->catfile( $dir => $new_file );
{
my $parent = Prophet::Util->updir($redirected_from);
# mkpath succeeds (but returns nothing) if a directory already exists
eval { mkpath( [$parent] ) };
if ( $@ ) {
die "Failed to create directory " . $parent . " - for $redirected_to " . $@;
}
}
if ( -d $redirected_from ) { $redirected_from .= "/index.html"; }
link( $redirected_to, $redirected_from );
}
sub write_file {
my $self = shift;
my $dir = shift;
my $file = shift;
my $content = shift;
if ( $file =~ qr|/$| ) {
$file .= "index.html"
} elsif ($file !~ /\.\w{2,4}$/) {
$file .= ".html";
}
Prophet::Util->write_file( file => File::Spec->catfile( $dir => $file ), content => $content );
}
__PACKAGE__->meta->make_immutable;
no Any::Moose;
package App::SD::Server::Static;
use Any::Moose;
extends 'App::SD::Server';
use Params::Validate;
use JSON;
sub log_request { }
sub send_content {
my $self = shift;
my %args = validate( @_, { content => 1, content_type => 0, encode_as => 0, static => 0 } );
if ( $args{'encode_as'} && $args{'encode_as'} eq 'json' ) {
$args{'content'} = to_json( $args{'content'} );
}
return $args{'content'};
}
sub _send_redirect {
my $self = shift;
my %args = validate( @_, { to => 1 } );
die "REDIRECT " . $args{to} . "\n";
}
sub _send_404 {}
__PACKAGE__->meta->make_immutable;
no Any::Moose;
1;
( run in 2.279 seconds using v1.01-cache-2.11-cpan-d8267643d1d )