Asset-Pack
view release on metacpan or search on metacpan
lib/Asset/Pack.pm view on Meta::CPAN
use 5.006; # our
use strict;
use warnings;
package Asset::Pack;
use Path::Tiny 0.069 qw( path ); # path()->visit without broken ref returns
use Try::Tiny qw( try catch );
our $VERSION = '0.000008';
# ABSTRACT: Easily pack assets into Perl Modules that can be fat-packed
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
use parent qw(Exporter);
our @EXPORT_OK = qw();
our @EXPORT = qw(write_module write_index find_and_pack);
#pod =func C<write_module>
#pod
#pod # write_module( $source, $module, $libdir?, $metadata? );
#pod
#pod write_module( "./foo.js", "Foo::Bar", "./" );
#pod
#pod # ./Foo/Bar.pm now contains a uuencoded copy of foo.js
#pod
#pod Given a source asset path, a module name and a library directory, packs the
#pod source into a module named C<$module> and saves it in the right place relative
#pod to C<$libdir>
#pod
#pod Later, getting the file is simple:
#pod
#pod use Foo::Bar;
#pod print $Foo::Bar::content; # File Content is a string.
#pod
#pod =head3 options:
#pod
#pod =over 4
#pod
#pod =item C<$source> - A path describing where the asset is found
#pod
#pod =item C<$module> - A target name for the generated module
#pod
#pod =item C<$libdir> B<[optional]> - A target directory to serve as a base for modules.
#pod
#pod Defaults to C<./lib>.
#pod
#pod =item C<$metadata> B<[optional]> - A C<HashRef> payload of additional data to store in the module.
#pod
#pod =back
#pod
#pod =cut
sub write_module {
my ( $source, $module, $libdir, $metadata ) = @_;
my $dest = _module_full_path( $module, $libdir );
$dest->parent->mkpath; # mkdir
$dest->spew_utf8( _pack_asset( $module, $source, $metadata ) );
return;
}
#pod =func C<write_index>
#pod
#pod # write_index( $index, $module, $libdir?, $metadata? );
#pod
#pod write_index( { "A" => "X.js" }, "Foo::Bar", "./" );
#pod
( run in 2.103 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )