App-PM-Website
view release on metacpan or search on metacpan
lib/App/PM/Website/Command/Install.pm view on Meta::CPAN
use strict;
use warnings;
package App::PM::Website::Command::Install;
{
$App::PM::Website::Command::Install::VERSION = '0.131611';
}
use base 'App::PM::Website::Command';
use Net::Netrc;
use HTTP::DAV;
use Data::Dumper;
#ABSTRACT: install the built website into production via caldav
sub options
{
my ($class, $app) = @_;
return (
[ 'url=s' => 'path to webdav directory' ],
[ 'build-dir=s' => 'path to local rendered files' ,
{ default => 'website' }],
[ 'filename=s' => 'upload name, rather than index.html' ,
{default => 'index.html'}],
[ 'username=s' => 'username for webdav, override .netrc' ],
[ 'password=s' => 'password for webdav, override .netrc' ],
[ 'certificate=s' => 'path to ca certificate' ],
);
}
sub validate
{
my ($self, $opt, $args ) = @_;
$self->validate_certificate($opt);
$self->validate_url($opt);
$self->validate_login($opt);
if(@$args)
{
die $self->usage_error("no arguments allowed")
}
}
sub validate_certificate
{
my ($self, $opt) = @_;
my $c = $self->{config}{config}{website};
$opt->{certificate} ||= $c->{certificate};
if ($opt->{certificate} && ! -f $opt->{certificate} )
{
die $self->usage_error("could not find certificate file: $opt->{certificate}");
}
return 1; #certificate is optional.
}
sub validate_url
{
my ($self, $opt ) = @_;
my $c = $self->{config}{config}{website};
$opt->{url} ||= $c->{url};
die $self->usage_error( "url must be defined on command line or in config file")
unless $opt->{url};
}
sub validate_login
{
my ( $self, $opt ) = @_;
my $c = $self->{config}{config}{website};
my $url = $opt->{url};
my $machine = $opt->{machine} || $c->{machine};
$opt->{username} ||= $c->{username};
$opt->{password} ||= $c->{password};
return 1 if ( $opt->{username} && $opt->{password} );
if( $machine )
{
my $mach = Net::Netrc->lookup($machine);
if ( defined $mach )
( run in 1.144 second using v1.01-cache-2.11-cpan-b16cb0d3907 )