aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/Skin.pm
diff options
context:
space:
mode:
authormatthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-01-30 16:33:10 +0000
committermatthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-01-30 16:33:10 +0000
commit8a293e2eee23938229a7dbfb617faee579914dfc (patch)
treef1626e9facac38a6b323c92e7d31585e5902cbba /lib/Reaction/UI/Skin.pm
parent46937531eb2d28950b21c8b0982539e28b277b60 (diff)
downloadreaction-8a293e2eee23938229a7dbfb617faee579914dfc.tar.gz
reaction-8a293e2eee23938229a7dbfb617faee579914dfc.zip
first cut of Reaction::UI::Skin and SiteLayout VP+widget
Diffstat (limited to 'lib/Reaction/UI/Skin.pm')
-rw-r--r--lib/Reaction/UI/Skin.pm91
1 files changed, 91 insertions, 0 deletions
diff --git a/lib/Reaction/UI/Skin.pm b/lib/Reaction/UI/Skin.pm
new file mode 100644
index 0000000..ff31a3a
--- /dev/null
+++ b/lib/Reaction/UI/Skin.pm
@@ -0,0 +1,91 @@
+package Reaction::UI::Skin;
+
+use Reaction::Class;
+
+# declaring dependencies
+use Reaction::UI::LayoutSet;
+use Reaction::UI::RenderingContext;
+
+use aliased 'Path::Class::Dir';
+
+class Skin which {
+
+ has '_layout_set_cache' => (is => 'ro', default => sub { {} });
+
+ has 'skin_base_path' => (is => 'ro', isa => Dir, required => 1);
+
+ has 'view' => (
+ is => 'ro', required => 1, weak_ref => 1,
+ handles => [ qw(layout_set_class) ],
+ );
+
+ has 'super' => (
+ is => 'rw', isa => Skin, required => 0, predicate => 'has_super',
+ );
+
+ sub BUILD {
+ my ($self) = @_;
+ $self->_load_skin_config;
+ }
+
+ implements '_load_skin_config' => as {
+ my ($self) = @_;
+ my $base = $self->skin_base_path;
+ confess "No such skin base directory ${base}"
+ unless -d $base;
+ }
+
+ implements 'create_layout_set' => as {
+ my ($self, $name) = @_;
+ if (my $path = $self->layout_path_for($name)) {
+ return $self->layout_set_class->new(
+ $self->layout_set_args_for($name),
+ source_file => $path,
+ );
+ }
+ if ($self->has_super) {
+ return $self->super->create_layout_set($name);
+ }
+ confess "Couldn't find layout set file for ${name}";
+ };
+
+ implements 'layout_set_args_for' => as {
+ my ($self, $name) = @_;
+ return (
+ name => $name,
+ view => $self->view,
+ skin => $self,
+ ($self->has_super ? (next_skin => $self->super) : ()),
+ $self->view->layout_set_args_for($name),
+ );
+ };
+
+ implements 'layout_path_for' => as {
+ my ($self, $layout) = @_;
+ my $file_name = join(
+ '.', $layout, $self->layout_set_class->file_extension
+ );
+ my $path = $self->our_path_for_type('layout')
+ ->file($file_name);
+ return (-e $path ? $path : undef);
+ };
+
+ implements 'search_path_for_type' => as {
+ my ($self, $type) = @_;
+ return [
+ $self->our_path_for_type($type),
+ ($self->has_super
+ ? @{$self->super->search_path_for_type($type)}
+ : ()
+ )
+ ];
+ };
+
+ implements 'our_path_for_type' => as {
+ my ($self, $type) = @_;
+ return $self->skin_base_path->subdir($type)
+ };
+
+};
+
+1;