NAME
Web::AssetLib::InputEngine - a base class for writing your own Input Engine
SYNOPSIS
package
My::Library::InputEngine;
use
Moose;
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
);
}
...
}
USAGE
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.
IMPLEMENTATION
load( $asset )
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.
METHODS
storeAssetContents
$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.
This is the only method that must be called when you implement the load() method.
All arguments are required.
addAssetToCache
$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.
getAssetFromCache
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.
SEE ALSO
Web::AssetLib::InputEngine::LocalFile
Web::AssetLib::InputEngine::RemoteFile
Web::AssetLib::InputEngine::Content
AUTHOR
Ryan Lang <rlang@cpan.org>