diff options
author | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-01-31 11:35:47 +0000 |
---|---|---|
committer | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-01-31 11:35:47 +0000 |
commit | a2a5872bdd576eb5f389499ed36b03b86587388d (patch) | |
tree | 8120f8e47751a10bb1363be4826a434c338fc99e | |
parent | f6b79841f315129d8e1261614efaa8253d286dee (diff) | |
download | reaction-a2a5872bdd576eb5f389499ed36b03b86587388d.tar.gz reaction-a2a5872bdd576eb5f389499ed36b03b86587388d.zip |
moved widget class search path to Skin
-rw-r--r-- | lib/Reaction/UI/Skin.pm | 44 | ||||
-rw-r--r-- | lib/Reaction/UI/View.pm | 25 | ||||
-rw-r--r-- | share/skin/componentui/layout/index.tt (renamed from share/skin/default/layout/index.tt) | 0 | ||||
-rw-r--r-- | share/skin/componentui/skin.conf | 2 |
4 files changed, 42 insertions, 29 deletions
diff --git a/lib/Reaction/UI/Skin.pm b/lib/Reaction/UI/Skin.pm index 8a29600..dad4206 100644 --- a/lib/Reaction/UI/Skin.pm +++ b/lib/Reaction/UI/Skin.pm @@ -11,14 +11,17 @@ use aliased 'Path::Class::Dir'; class Skin which { has '_layout_set_cache' => (is => 'ro', default => sub { {} }); + has '_widget_class_cache' => (is => 'ro', default => sub { {} }); has 'skin_base_path' => (is => 'ro', isa => Dir, required => 1); - has 'widget_search_path' => (is => 'rw', isa => 'ArrayRef', lazy_fail => 1); + has 'widget_search_path' => ( + is => 'rw', isa => 'ArrayRef', requred => 1, default => sub { [] } + ); has 'view' => ( is => 'ro', required => 1, weak_ref => 1, - handles => [ qw(layout_set_class widget_class_for) ], + handles => [ qw(layout_set_class) ], ); has 'super' => ( @@ -35,7 +38,7 @@ class Skin which { my $base = $self->skin_base_path; confess "No such skin base directory ${base}" unless -d $base; - my $lst = sub { (ref $_[0] eq 'ARRAY') ? $_[0]: [$_[0]] }; + my $lst = sub { (ref $_[0] eq 'ARRAY') ? $_[0] : [$_[0]] }; my @files = ( $base->parent->file('defaults.conf'), $base->file('skin.conf') ); @@ -56,7 +59,9 @@ class Skin which { if (exists $cfg{widget_search_path}) { $self->widget_search_path($lst->($cfg{widget_search_path})); } else { - confess "No widget_search_path in defaults.conf or skin.conf"; + confess "No widget_search_path in defaults.conf or skin.conf" + ." and no search path provided from super skin" + unless $self->full_widget_search_path; } } @@ -110,6 +115,37 @@ class Skin which { return $self->skin_base_path->subdir($type) }; + implements 'full_widget_search_path' => as { + my ($self) = @_; + return ( + @{$self->widget_search_path}, + ($self->has_super ? $self->super->full_widget_search_path : ()) + ); + }; + + implements 'widget_class_for' => as { + my ($self, $layout_set) = @_; + my $base = $self->blessed; + my $widget_type = $layout_set->widget_type; + return $self->_widget_class_cache->{$widget_type} ||= do { + + my @search_path = $self->full_widget_search_path; + my @haystack = map {join('::', $_, $widget_type)} @search_path; + + foreach my $class (@haystack) { + #if the class is already loaded skip the call to Installed etc. + return $class if Class::MOP::is_class_loaded($class); + next unless Class::Inspector->installed($class); + + my $ok = eval { Class::MOP::load_class($class) }; + confess("Failed to load widget '${class}': $@") if $@; + return $class; + } + confess "Couldn't locate widget '${widget_type}' for layout " + ."'${\$layout_set->name}': tried: ".join(", ", @haystack); + }; + }; + }; 1; diff --git a/lib/Reaction/UI/View.pm b/lib/Reaction/UI/View.pm index 1b492b8..d8638a3 100644 --- a/lib/Reaction/UI/View.pm +++ b/lib/Reaction/UI/View.pm @@ -10,7 +10,6 @@ use aliased 'Path::Class::Dir'; class View which { - has '_widget_class_cache' => (is => 'ro', default => sub { {} }); has '_widget_cache' => (is => 'ro', default => sub { {} }); has '_layout_set_cache' => (is => 'ro', default => sub { {} }); @@ -77,30 +76,6 @@ class View which { ); }; - implements 'widget_class_for' => as { - my ($self, $layout_set) = @_; - my $base = $self->blessed; - my $widget_type = $layout_set->widget_type; - my $app_name = ref $self->app || $self->app; - return $self->_widget_class_cache->{$widget_type} ||= do { - - my @search_path = ($base, $app_name, 'Reaction::UI'); - my @haystack = map {join('::', $_, 'Widget', $widget_type)} @search_path; - - foreach my $class (@haystack) { - #if the class is already loaded skip the call to Installed etc. - return $class if Class::MOP::is_class_loaded($class); - next unless Class::Inspector->installed($class); - - my $ok = eval { Class::MOP::load_class($class) }; - confess("Failed to load widget '${class}': $@") if $@; - return $class; - } - confess "Couldn't locate widget '${widget_type}' for layout " - ."'${\$layout_set->name}': tried: ".join(", ", @haystack); - }; - }; - implements 'layout_set_for' => as { my ($self, $vp) = @_; #print STDERR "Getting layoutset for VP ".(ref($vp) || "SC:".$vp)."\n"; diff --git a/share/skin/default/layout/index.tt b/share/skin/componentui/layout/index.tt index 9a9bc9c..9a9bc9c 100644 --- a/share/skin/default/layout/index.tt +++ b/share/skin/componentui/layout/index.tt diff --git a/share/skin/componentui/skin.conf b/share/skin/componentui/skin.conf index a9827b2..0fa450d 100644 --- a/share/skin/componentui/skin.conf +++ b/share/skin/componentui/skin.conf @@ -1 +1,3 @@ extends default + +widget_search_path ComponentUI::View::Site::Widget |