AWS-Lambda-Quick
view release on metacpan or search on metacpan
lib/AWS/Lambda/Quick/CreateZip.pm view on Meta::CPAN
return $src;
};
### methods for interfacing with Archive::Zip
### no code outside this section should directly interact with the
### zip file
sub _add_string {
my $self = shift;
my $string = shift;
my $filename = shift;
my $zip = $self->_zip;
my $string_member = $zip->addString( $string, $filename );
$string_member->desiredCompressionMethod(COMPRESSION_DEFLATED);
return ();
}
sub _add_path {
my $self = shift;
my $path = path(shift);
if ( $path->is_absolute ) {
die "Cannot add absolute path! $path";
}
my $abs_path = path( $self->_src_dir, $path );
# silently ignore files that don't exist. This allows you
# to say put extra_files => [qw( lib )] in your file and not
# worry if that file exists or not
return unless -e $abs_path;
$self->_zip->addFileOrDirectory(
{
name => $abs_path->stringify,
zipName => $path->stringify,
compressionLevel => COMPRESSION_DEFLATED,
}
);
# was that a directory? Add the contents recursively
return () unless -d $abs_path;
my $iter = $abs_path->iterator;
while ( my $next = $iter->() ) {
my $child = $path->child( $next->basename );
$self->_add_path($child);
}
return ();
}
sub _write_zip {
my $self = shift;
unless ( $self->_zip->writeToFileNamed( $self->zip_filename->stringify )
== AZ_OK ) {
die 'write error';
}
return ();
}
### logic for building the zip file contents ###
sub _build_zip {
my $self = shift;
$self->_add_string( $self->_converted_src, 'handler.pl' );
$self->_add_path($_) for @{ $self->extra_files };
return ();
}
sub create_zip {
my $self = shift;
$self->_build_zip;
$self->_write_zip;
return ();
}
1;
__END__
=head1 NAME
AWS::Lambda::Quick::CreateZip - lambda function zipping for AWS::Lambda::Quick
=head1 DESCRIPTION
No user servicable parts. See L<AWS::Lambda::Quick> for usage.
=head1 AUTHOR
Written by Mark Fowler B<mark@twoshortplanks.com>
Copyright Mark Fowler 2019.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
L<AWS::Lambda::Quick>
=cut
( run in 1.675 second using v1.01-cache-2.11-cpan-f56aa216473 )