| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package JavaScript::Librarian; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
JavaScript::Librarian - Load and use libraries of JavaScript packages |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
C is a package for loading and using "libraries" |
|
12
|
|
|
|
|
|
|
of JavaScript packages, managing dependencies between the files, and |
|
13
|
|
|
|
|
|
|
generating fragments of HTML with the EscriptE tags to load them |
|
14
|
|
|
|
|
|
|
in the correct order. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 STATUS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This is an early release, and while it implements the core object and |
|
19
|
|
|
|
|
|
|
logic, this package does not yet come with any |
|
20
|
|
|
|
|
|
|
L sub-classes capable of loading |
|
21
|
|
|
|
|
|
|
the required metadata from anything. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This will be dealth with in a seperate package, or in a future version |
|
24
|
|
|
|
|
|
|
of this one. For the moment consider it something you can use to build |
|
25
|
|
|
|
|
|
|
your own modules. See the source code for more documentation. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
|
28
|
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
1234
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
30
|
1
|
|
|
1
|
|
851
|
use URI (); |
|
|
1
|
|
|
|
|
5019
|
|
|
|
1
|
|
|
|
|
18
|
|
|
31
|
1
|
|
|
1
|
|
844
|
use Clone (); |
|
|
1
|
|
|
|
|
3118
|
|
|
|
1
|
|
|
|
|
23
|
|
|
32
|
1
|
|
|
1
|
|
9
|
use File::Spec::Unix (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
33
|
1
|
|
|
1
|
|
810
|
use Algorithm::Dependency::Ordered (); |
|
|
1
|
|
|
|
|
8591
|
|
|
|
1
|
|
|
|
|
19
|
|
|
34
|
1
|
|
|
1
|
|
531
|
use JavaScript::Librarian::Book (); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
14
|
|
|
35
|
1
|
|
|
1
|
|
469
|
use JavaScript::Librarian::Library (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
36
|
1
|
|
|
1
|
|
912
|
use Params::Coerce '_URI' => 'URI'; |
|
|
1
|
|
|
|
|
1379
|
|
|
|
1
|
|
|
|
|
4
|
|
|
37
|
1
|
|
|
1
|
|
199
|
use Params::Coerce '_Library' => 'JavaScript::Librarian::Library'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
123
|
use vars qw{$VERSION}; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
40
|
|
|
|
|
|
|
BEGIN { |
|
41
|
1
|
|
|
1
|
|
521
|
$VERSION = '1.00'; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
##################################################################### |
|
49
|
|
|
|
|
|
|
# Constructor and Accessors |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
|
52
|
0
|
0
|
|
0
|
0
|
|
my $class = ref $_[0] ? ref shift : shift; |
|
53
|
0
|
|
|
|
|
|
my %args = @_; |
|
54
|
0
|
0
|
|
|
|
|
my $base = $class->_URI($args{base}) or return undef; |
|
55
|
0
|
0
|
|
|
|
|
my $library = $class->_Library($args{library}) or return undef; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Create the dependency resolver |
|
58
|
0
|
0
|
|
|
|
|
my $resolver = Algorithm::Dependency::Ordered->new( |
|
59
|
|
|
|
|
|
|
source => $library, |
|
60
|
|
|
|
|
|
|
ignore_orphans => 1, |
|
61
|
|
|
|
|
|
|
) or return undef; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Create the basic object |
|
64
|
0
|
|
|
|
|
|
my $self = bless { |
|
65
|
|
|
|
|
|
|
base => $base, |
|
66
|
|
|
|
|
|
|
library => $library, |
|
67
|
|
|
|
|
|
|
resolver => $resolver, |
|
68
|
|
|
|
|
|
|
selected => {}, |
|
69
|
|
|
|
|
|
|
}, $class; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Add any packages to select passed to the constructor |
|
72
|
0
|
0
|
|
|
|
|
if ( ref $args{select} eq 'ARRAY' ) { |
|
73
|
0
|
|
|
|
|
|
foreach my $book ( @{$args{select}} ) { |
|
|
0
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
$self->select( $_ ) or return undef; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub base { |
|
82
|
0
|
|
|
0
|
0
|
|
Clone::clone $_[0]->{base}; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub library { |
|
86
|
0
|
|
|
0
|
0
|
|
$_[0]->{library}; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub resolver { |
|
90
|
0
|
|
|
0
|
0
|
|
$_[0]->{resolver}; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
##################################################################### |
|
99
|
|
|
|
|
|
|
# Main Methods |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Select a package we need |
|
102
|
|
|
|
|
|
|
sub add { |
|
103
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
104
|
0
|
0
|
|
|
|
|
my $book = $self->library->item($_[0]) ? shift : return undef; |
|
105
|
0
|
|
|
|
|
|
$self->{selected}->{$book} = 1; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Find the schedule for the currently selected items |
|
109
|
|
|
|
|
|
|
sub schedule { |
|
110
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
111
|
0
|
|
|
|
|
|
$self->resolver->schedule( sort keys %{$self->{selected}} ); |
|
|
0
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Get the list of paths of JavaScript files to load |
|
115
|
|
|
|
|
|
|
sub paths { |
|
116
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
117
|
0
|
0
|
|
|
|
|
my $schedule = $self->schedule or return undef; |
|
118
|
0
|
|
|
|
|
|
my $library = $self->library; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Map to file names |
|
121
|
0
|
|
|
|
|
|
my @paths = map { $library->item($_)->path } @$schedule; |
|
|
0
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Move them under the base URI |
|
124
|
0
|
|
|
|
|
|
@paths = map { $self->_path_URI($_) } @paths; |
|
|
0
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
\@paths; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Generate a URI relative to the base, but without the assumption that |
|
130
|
|
|
|
|
|
|
# the base URI is absolute. |
|
131
|
|
|
|
|
|
|
sub _path_URI { |
|
132
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
133
|
0
|
|
|
|
|
|
my $URI = $self->base; |
|
134
|
0
|
|
|
|
|
|
my $path = File::Spec::Unix->catfile( $URI->path, @_ ); |
|
135
|
0
|
|
|
|
|
|
$URI->path( $path ); |
|
136
|
0
|
|
|
|
|
|
$URI; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Generates a string of HTML to load the books |
|
140
|
|
|
|
|
|
|
sub html { |
|
141
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
142
|
0
|
0
|
|
|
|
|
my $paths = $self->paths or return undef; |
|
143
|
0
|
|
|
|
|
|
join "\n", map { |
|
144
|
0
|
|
|
|
|
|
qq~~ |
|
145
|
|
|
|
|
|
|
} @$paths; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# XHTML version of the above...? |
|
149
|
|
|
|
|
|
|
sub xhtml { |
|
150
|
0
|
|
|
0
|
0
|
|
''; ### FIXME - Finish this |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=pod |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SUPPORT |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Bugs should always be submitted via the CPAN bug tracker |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
L |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
For other issues, contact the maintainer |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHORS |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Adam Kennedy Ecpan@ali.asE, L |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Copyright (c) 2005 Adam Kennedy. All rights reserved. |
|
172
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
173
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
176
|
|
|
|
|
|
|
LICENSE file included with this module. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |