package JS::jQuery::Loader; use warnings; use strict; =head1 NAME JS::jQuery::Loader - Load (and cache) the jQuery JavaScript library =head1 VERSION Version 0.01 =head1 jQuery VERSION Version 1.2.3 =cut our $VERSION = '0.01'; use constant JQUERY_VERSION => "1.2.3"; =head1 SYNOPSIS use JS::jQuery::Loader; my $loader = JS::jQuery::Loader->new_from_internet; print $loader->html; # The above will yield: # =cut sub html { my $self = shift; return $self->_html($self->uri); } =head2 $loader->source_html Generate and return a string containing HTML describing how to include components. For example, you can use this in the
section of a web page. Here is an example: =cut sub source_html { my $self = shift; return $self->_html($self->source->uri); } sub _new_given { my $class = shift; return @_ == 1 && ref $_[0] eq "HASH" ? shift : { @_ }; } sub _new_template { my $class = shift; my $given = shift; my $template = delete $given->{template} || {}; $template->{version} = delete $given->{version} if defined $given->{version}; $template->{filter} = delete $given->{filter} if defined $given->{filter}; $template->{version} ||= JQUERY_VERSION; return $given->{template} = $template if blessed $template; return $given->{template} = JS::jQuery::Loader::Template->new(%$template); } sub _build_cache { my $class = shift; my $given = shift; my $source = shift; my (%cache, $cache_class); if (ref $given eq "HASH") { $cache_class = "JS::jQuery::Loader::Cache::URI"; my ($uri, $file, $dir) = @$given{qw/uri file dir/}; %cache = (uri => $uri, file => $file, dir => $dir); } elsif (ref $given eq "Path::Resource") { $cache_class = "JS::jQuery::Loader::Cache::URI"; %cache = (uri => $given->uri, file => $given->file); } else { $cache_class = "JS::jQuery::Loader::Cache::File"; %cache = (file => $given); } eval "require $cache_class;" or die $@; return $cache_class->new(source => $source, %cache); } sub _new_cache { my $class = shift; my $given = shift; my $source = shift; if (my $cache = delete $given->{cache}) { $given->{cache} = $class->_build_cache($cache, $source); } } sub _new_given_template { my $class = shift; my $given = $class->_new_given(@_); my $template = $class->_new_template($given); return ($given, $template); } sub _new_finish { my $class = shift; my $given = shift; my $source = shift; $class->_new_cache($given, $source); return $class->new(%$given, source => $source); } =head1 AUTHOR Robert Krimen, C<<