Dist-Zilla-BeLike-CSJEWELL

changeset 11:101ce8648cb6

Adding FTP upload plugin.
author Curtis Jewell <csjewell@cpan.org>
date Fri Aug 13 10:18:46 2010 -0600 (2010-08-13)
parents a6ab0fab9619
children 1fe391f06a8e
files lib/Dist/Zilla/Plugin/CSJEWELL/FTPUploadToOwnSite.pm
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/Dist/Zilla/Plugin/CSJEWELL/FTPUploadToOwnSite.pm	Fri Aug 13 10:18:46 2010 -0600
     1.3 @@ -0,0 +1,179 @@
     1.4 +package Dist::Zilla::Plugin::CSJEWELL::FTPUploadToOwnSite;
     1.5 +
     1.6 +use 5.008003;
     1.7 +use Moose;
     1.8 +use Net::Netrc;
     1.9 +use Net::FTP;
    1.10 +with 'Dist::Zilla::Role::Releaser';
    1.11 +
    1.12 +our $VERSION = '0.900';
    1.13 +$VERSION =~ s/_//sm;
    1.14 +
    1.15 +has site => (
    1.16 +  is   => 'ro',
    1.17 +  isa  => 'Str',
    1.18 +  required => 1,
    1.19 +);
    1.20 +
    1.21 +has directory => (
    1.22 +  is   => 'ro',
    1.23 +  isa  => 'Str',
    1.24 +  required => 1,
    1.25 +);
    1.26 +
    1.27 +has passive_ftp => (
    1.28 +  is   => 'ro',
    1.29 +  isa  => 'Int',
    1.30 +  default => 1,
    1.31 +);
    1.32 +
    1.33 +has debug => (
    1.34 +  is   => 'ro',
    1.35 +  isa  => 'Int',
    1.36 +  default => 0,
    1.37 +);
    1.38 +
    1.39 +sub release {
    1.40 +	my ($self, $archive) = @_;
    1.41 +
    1.42 +	my $site = $self->site();
    1.43 +	my $siteinfo = Net::Netrc->lookup($self->site());
    1.44 +	my ($user, $password, undef) = $siteinfo->lpa();
    1.45 +	
    1.46 +	my $ftp = Net::FTP->new(
    1.47 +		$site,
    1.48 +		Debug   => $self->debug(),
    1.49 +		Passive => $self->passive_ftp(),
    1.50 +	);
    1.51 +	
    1.52 +	$ftp->login($user, $password) or $self->log_fatal("Could not log in to " . $site);
    1.53 +	
    1.54 +	$ftp->binary;
    1.55 +
    1.56 +	$ftp->cwd($self->directory()) or $self->log_fatal("Could not change remote site directory to" . $self->directory());
    1.57 +	
    1.58 +	my $remote_file = $ftp->put($archive, $archive);
    1.59 +	
    1.60 +	if ( $remote_file ne $archive ) {
    1.61 +		$self->log_fatal( "Could not upload file: " . $ftp->message );
    1.62 +	}
    1.63 +	
    1.64 +	my $remote_size = $ftp->size( $self->remote_file );
    1.65 +	$remote_size ||= 0;
    1.66 +	my $local_size = -s $archive;
    1.67 +	
    1.68 +	if ($remote_size != $local_size) {
    1.69 +		$self->log("Uploaded file is $remote_size bytes, " .
    1.70 +			"but local file is $local_size bytes")
    1.71 +	}
    1.72 +
    1.73 +	$ftp->quit;
    1.74 +
    1.75 +	print "File uploaded to " . $self->site();
    1.76 +
    1.77 +	return 1;
    1.78 +}
    1.79 +
    1.80 +__PACKAGE__->meta()->make_immutable();
    1.81 +no Moose;
    1.82 +1;
    1.83 +
    1.84 +__END__
    1.85 +
    1.86 +=pod
    1.87 +
    1.88 +=head1 NAME
    1.89 +
    1.90 +Dist::Zilla::Plugin::CSJEWELL::FTPUploadToOwnSite - Upload tarball to my own site
    1.91 +
    1.92 +=head1 VERSION
    1.93 +
    1.94 +This document describes Dist::Zilla::Plugin::CSJEWELL::FTPUploadToOwnSite version 0.900.
    1.95 +
    1.96 +=head1 DESCRIPTION
    1.97 +
    1.98 +	; in dzil.ini
    1.99 +	[CSJEWELL::FTPUploadToOwnSite]
   1.100 +	site        = ftp.geocities.invalid
   1.101 +	directory   = /Heartland/Meadows/3044
   1.102 +	passive_ftp = 1
   1.103 +	debug       = 0
   1.104 +	
   1.105 +	# in $HOME/.netrc
   1.106 +	ftp.geocities.invalid csjewell password
   1.107 +
   1.108 +=head1 INTERFACE
   1.109 +
   1.110 +=head2 dzil.ini file
   1.111 +
   1.112 +The dzil.ini file takes 4 parameters, two of which are required.
   1.113 +
   1.114 +=head3 site
   1.115 +
   1.116 +The FTP site to upload to.
   1.117 +
   1.118 +=head3 directory
   1.119 +
   1.120 +The directory on the FTP site to upload the tarball to.
   1.121 +
   1.122 +=head3 passive_ftp
   1.123 +
   1.124 +Whether to use passive FTP or not. Defaults to 1.
   1.125 +
   1.126 +=head3 debug
   1.127 +
   1.128 +Tells Net::FTP to print out its debug messages.  Defaults to 0.
   1.129 +
   1.130 +=head2 .netrc file
   1.131 +
   1.132 +The .netrc file is described in L<Net::Netrc|Net::Netrc> and should have an 
   1.133 +entry in it, matching the site given in the dzil.ini file, and specifying 
   1.134 +the username and password.
   1.135 +
   1.136 +=for Pod::Coverage release
   1.137 +
   1.138 +=head1 AUTHOR
   1.139 +
   1.140 +Curtis Jewell <CSJewell@cpan.org>
   1.141 +
   1.142 +=head1 SEE ALSO
   1.143 +
   1.144 +L<Dist::Zilla::BeLike::CSJEWELL|Dist::Zilla::BeLike::CSJEWELL>
   1.145 +
   1.146 +=head1 LICENSE AND COPYRIGHT
   1.147 +
   1.148 +Copyright (c) 2010, Curtis Jewell C<< CSJewell@cpan.org >>.
   1.149 +
   1.150 +This module is free software; you can redistribute it and/or
   1.151 +modify it under the same terms as Perl itself, either version
   1.152 +5.8.1 or any later version. See L<perlartistic|perlartistic> 
   1.153 +and L<perlgpl|perlgpl>.
   1.154 +
   1.155 +The full text of the license can be found in the
   1.156 +LICENSE file included with this module.
   1.157 +
   1.158 +=head1 DISCLAIMER OF WARRANTY
   1.159 +
   1.160 +BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
   1.161 +FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
   1.162 +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
   1.163 +PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
   1.164 +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   1.165 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
   1.166 +ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
   1.167 +YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
   1.168 +NECESSARY SERVICING, REPAIR, OR CORRECTION.
   1.169 +
   1.170 +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
   1.171 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
   1.172 +REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
   1.173 +LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
   1.174 +OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
   1.175 +THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
   1.176 +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
   1.177 +FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
   1.178 +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
   1.179 +SUCH DAMAGES.
   1.180 +
   1.181 +=cut
   1.182 +