BEGIN { use_ok(
'HTML::ScriptLoader'
) };
my
%scripts
= (
'other-script'
=> {
},
'myscript'
=> {
'uri'
=>
'/static/js/myscript.js'
,
'deps'
=> [
'other-script'
],
'params'
=> {
'apikey'
=>
'very-secret'
,
},
},
);
my
$loader
= HTML::ScriptLoader->new(\
%scripts
);
ok(
$loader
);
is(
scalar
keys
%{
$loader
->available }, 2,
"The number of available scripts"
);
is(
scalar
@{
$loader
->scripts }, 0,
"The number of loaded scripts is 0 to begin with"
);
$loader
->add_script(
qw/myscript/
);
is(
scalar
@{
$loader
->scripts }, 2,
"The number of loaded scripts is 2 after loading myscript (dep on other-script)"
);
my
$otherscript
=
$loader
->scripts->[0];
my
$myscript
=
$loader
->scripts->[1];
is(
$myscript
->{
'url'
},
'/static/js/myscript.js?apikey=very-secret'
,
"Assemble the myscript URL with params"
);