Web::AssetLib::InputEngine - a base class for writing your own Input Engine
package My::Library::InputEngine; use Moose; extends 'Web::AssetLib::InputEngine'; sub load { my ( $self, $asset ) = @_; # your special file handing for $asset # store the digest and contents with the asset $self->storeAssetContents( asset => $asset, digest => $digest, contents => $contents ); }
Using the cache:
sub load { ... unless( $self->getAssetFromCache($digest) ){ # not in cache, so load it my $contents = ...; # add it to the cache $self->addAssetToCache( $digest => $contents ); } ... }
If you have a need for a special file input scenario, you can simply extend this class, and it will plug in to the rest of the Web::AssetLib pipeline.
The only requirement is that your Input Engine implements the load( $asset ) method. Load your file however you wish, and then call storeAssetContents.
Optionally, you may utilize the cache, with the addAssetToCache and getAssetFromCache methods.
Load/consume an asset represented by $asset, which will be a Web::AssetLib::Asset object. Load however you'd like, then call storeAssetContents to store the file for later use in the pipeline.
$asset
$engine->storeAssetContents( asset => $asset, digest => $digest, contents => $contents );
Associates the file contents and digest with the asset instance. $asset should be a Web::AssetLib::Asset object, and $contents and $digest must be strings.
$contents
$digest
This is the only method that must be called when you implement the load() method.
All arguments are required.
$engine->addAssetToCache( digest => $digest );
Creates a mapping between your file $digest and file $contents in the cache. It is reccomended that the cache be utilized when implementing load() but it is not a requirement.
my $asset = $engine->getAssetFromCache( $digest );
Returns file contents associated with the digest if present in cache, otherwise returns undef. It is reccomended that the cache be utilized when implementing load() but it is not a requirement.
Web::AssetLib::InputEngine::LocalFile
Web::AssetLib::InputEngine::RemoteFile
Web::AssetLib::InputEngine::Content
Ryan Lang <rlang@cpan.org>
To install Web::AssetLib, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Web::AssetLib
CPAN shell
perl -MCPAN -e shell install Web::AssetLib
For more information on module installation, please visit the detailed CPAN module installation guide.