Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
make sure the required scripts inside the child's realize method are …
Browse files Browse the repository at this point in the history
…placed in the correct order
  • Loading branch information
urandom committed Nov 11, 2008
1 parent 4e29e6a commit d4d5b49
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name 'IWL';
all_from 'lib/IWL.pm';
license 'perl';

requires 'Locale::Messages';
requires 'Locale::TextDomain' => 1.10;
requires 'File::ShareDir' => 0.05;
requires 'HTML::Parser' => 2.25;
Expand Down
16 changes: 11 additions & 5 deletions lib/IWL/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1750,11 +1750,17 @@ sub __addRequired {

$top->{___lastShared} = $scripts[-1];

$script && $script->{parentNode}
? $script->{parentNode}->insertBefore($script, @scripts)
: $pivot && $pivot->{parentNode}
? $pivot->{parentNode}->insertAfter($pivot, @scripts)
: ($body || $self)->appendChild(@scripts);
if ($script && $script->{parentNode}) {
$script->{parentNode}->insertBefore($script, @scripts);
} elsif ($pivot && $pivot->{parentNode}) {
if ($self != $top) {
my $last = $pivot->next({package => 'IWL::Script'}, {attribute => ['iwl:requiredScript']});
$pivot = $last if $last;
}
$pivot->{parentNode}->insertAfter($pivot, @scripts);
} else {
($body || $self)->appendChild(@scripts);
}

if (ref $required{css} eq 'ARRAY') {
if ($head) {
Expand Down
17 changes: 13 additions & 4 deletions t/10object.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test::More tests => 126;
use Test::More tests => 128;

use IWL::Object;
use IWL::Config '%IWLConfig';
Expand Down Expand Up @@ -155,8 +155,10 @@ my $output;
$o2 = IWL::Test::Object2->new;
$o->appendChild($o2);
$data = $o->getObject;
is($data->{children}[0]{children}[0]{children}[0]{text}, qq(\@import "/my/skin/darkness/foo.css";\n));
is($data->{children}[1]{attributes}{src}, '/jscript/foo.js');
is($data->{children}[0]{children}[0]{text}, qq(\@import "/my/skin/darkness/foo.css";\n));
is($data->{children}[1]{children}[0]{children}[0]{text}, qq(\@import "/my/skin/darkness/bar.css";\n));
is($data->{children}[2]{attributes}{src}, '/jscript/foo.js');
is($data->{children}[3]{attributes}{src}, '/jscript/bar.js');
}

{
Expand Down Expand Up @@ -268,8 +270,15 @@ package IWL::Test::Object2;

use base 'IWL::Object';

sub new {
my $self = shift->SUPER::new;

$self->require(js => 'foo.js', css => 'foo.css');
return $self;
}

sub _realize {
my $self = shift;
$self->require(js => 'foo.js', css => 'foo.css');
$self->require(js => 'bar.js', css => 'bar.css');
$self->SUPER::_realize;
}

0 comments on commit d4d5b49

Please sign in to comment.