JavaScript-Librarian
view release on metacpan or search on metacpan
lib/JavaScript/Librarian.pm view on Meta::CPAN
sub resolver {
$_[0]->{resolver};
}
#####################################################################
# Main Methods
# Select a package we need
sub add {
my $self = shift;
my $book = $self->library->item($_[0]) ? shift : return undef;
$self->{selected}->{$book} = 1;
}
# Find the schedule for the currently selected items
sub schedule {
my $self = shift;
$self->resolver->schedule( sort keys %{$self->{selected}} );
}
# Get the list of paths of JavaScript files to load
sub paths {
my $self = shift;
my $schedule = $self->schedule or return undef;
my $library = $self->library;
# Map to file names
my @paths = map { $library->item($_)->path } @$schedule;
# Move them under the base URI
@paths = map { $self->_path_URI($_) } @paths;
\@paths;
}
# Generate a URI relative to the base, but without the assumption that
# the base URI is absolute.
sub _path_URI {
my $self = shift;
my $URI = $self->base;
my $path = File::Spec::Unix->catfile( $URI->path, @_ );
$URI->path( $path );
$URI;
}
# Generates a string of HTML to load the books
sub html {
my $self = shift;
my $paths = $self->paths or return undef;
join "\n", map {
qq~<script language="JavaScript" src="$_" type="text/javascript"></script>~
} @$paths;
}
# XHTML version of the above...?
sub xhtml {
''; ### FIXME - Finish this
}
1;
=pod
=head1 SUPPORT
Bugs should always be submitted via the CPAN bug tracker
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=JavaScript-Librarian>
For other issues, contact the maintainer
=head1 AUTHORS
Adam Kennedy E<lt>cpan@ali.asE<gt>, L<http://ali.as/>
=head1 COPYRIGHT
Copyright (c) 2005 Adam Kennedy. All rights reserved.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=cut
( run in 0.886 second using v1.01-cache-2.11-cpan-119454b85a5 )