NAME
Web::Library - Manager for wrappers around client-side libraries
SYNOPSIS
# in your Catalyst application:
my $library_manager = Web::Library->instance;
$library_manager->mount_library({ name => 'jQuery' });
$library_manager->mount_library(
{ name => 'Bootstrap', version => '2.3.0' });
__PACKAGE__->config(
'Plugin::Static::Simple' => {
include_path => [ $library_manager->include_paths ] },
...
);
# in an HTML template
...
[% web_library.css_link_tags_for('Bootstrap', 'jQuery') %]
...
[% web_library.script_tags_for('Bootstrap', 'jQuery') %]
DESCRIPTION
There are well-established ways for web applications to manage
server-side dependencies, like "Makefile.PL" or "cpanfile" - but what
about client-side dependencies?
So you develop and maintain a number of web applications, and all of
them use some client-side libraries like jQuery or Twitter Bootstrap or
Underscore.js. You have to copy the relevant JavaScript, CSS and image
files to a directory containing static files for each web application.
This involves quite a bit of copying around and version maintenance.
Web::Library can help you.
The idea behind Web::Library and its related distributions is that
client-side libraries are installed as shared files of standard CPAN
distributions. Web::Library itself is a manager for those libraries. A
web application that wishes to use one or more client-side libraries can
tell Web::Library to include either the latest or a specific version of
those libraries. These managed libraries can then be used as static
files with web application frameworks. In the case of Catalyst you might
use Catalyst::Plugin::Static::Simple as shown in the synopsis.
Web::Library is a singleton object, so you can add client-side libraries
in different parts of your application. For example, you might have
common librares that are included in all of your web applications, but
then also want to manage application-specific libraries.
Only client-side libraries whose license permits redistribution can be
managed this way. Forunately, most, if not all, popular client-side
libraries have such permissive licenses.
METHODS
instance
Returns the singleton Web::Library object that manages all
client-side libraries.
mount_library
Adds a specific version of a client-side library to the list of
managed libraries. Takes a hashref of named parameters. Valid
parameters are:
name
The name of the client-side library. The manager will try to
load the "Web::Library::$name" class. For example,
Web::Library::Bootstrap is a distribution wrapper for Twitter
Bootstrap.
version
A distribution wrapper will contain various versions of the
wrapped client-side library. Using this parameter you can
specify the version you want. Refer to the relevant
distribution's documentation to see which versions are
available. This parameter is optional; if omitted, the latest
version is used.
include_paths
Client-side library files are installed as shared files as described
in File::ShareDir. The "include_paths" method returns the absolute
paths to shared directories for all managed libraries.
Returns a list in list context and an array reference in scalar
context.
reset
Clears all mounted libraries.
ASSET-RELATED METHODS
Web::Library can also help you with including a library's CSS and
JavaScript files in the web page templates.
If you expose an instance of Web::Library to your templates, you can add
the relevant "" and "