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 { {} });
has 'app' => (is => 'ro', required => 1);
- has 'skin_name' => (is => 'ro', required => 1);
+ has 'skin_name' => (is => 'ro', required => 1, default => 'default');
has 'skin' => (
is => 'ro', lazy_build => 1,
my ($self) = @_;
Skin->new(
name => $self->skin_name, view => $self,
- skin_base_path => # returns a File, not a Dir. Thanks, Catalyst.
- Dir->new($self->app->path_to('share', 'skin', $self->skin_name)),
+ # path_to returns a File, not a Dir. Thanks, Catalyst.
+ skin_base_dir => Dir->new($self->app->path_to('share', 'skin')),
);
};
);
};
- 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;
- my $found;
- foreach my $class (@haystack) {
- #here we should throw if exits and error instead of eating the error
- #only next when !exists
- eval { Class::MOP::load_class($class) };
- #$@ ? next : return $class;
- #warn "Loaded ${class}" unless $@;
- #warn "Boom loading ${class}: $@" if $@;
- unless ($@) {
- $found = $class;
- last;
- }
- }
- unless ($found) {
- confess "Couldn't load widget '${widget_type}'"
- ." for layout '${\$layout_set->name}':"
- ." tried: ".join(", ", @haystack);
- }
- $found;
- };
- };
-
implements 'layout_set_for' => as {
my ($self, $vp) = @_;
- #print STDERR "Getting layoutset for VP ".(ref($vp) || "SC:".$vp)."\n";
my $lset_name = eval { $vp->layout };
confess "Couldn't call layout method on \$vp arg ${vp}: $@" if $@;
- unless (length($lset_name)) {
- my $vp_class = ref($vp) || $vp;
- my ($last) = ($vp_class =~ /.*(?:::ViewPort::)(.+?)$/);
- my @fragments = split('::', $last);
- $_ = join("_", split(/(?=[A-Z])/, $_)) for @fragments;
- $lset_name = lc(join('/', @fragments));
- #print STDERR "--- $vp_class is rendered as $lset_name\n";
- }
+ $lset_name = $self->layout_set_name_from_viewport( blessed($vp) )
+ unless (length($lset_name));
my $cache = $self->_layout_set_cache;
return $cache->{$lset_name} ||= $self->create_layout_set($lset_name);
};
+ #XXX if it ever comes to it: this could be memoized. not bothering yet.
+ implements 'layout_set_name_from_viewport' => as {
+ my ($self, $class) = @_;
+ my ($last) = ($class =~ /.*(?:::ViewPort::)(.+?)$/);
+ #split when a non-uppercase letter meets an uppercase or when an
+ #uppercase letter is followed by another uppercase and then a non-uppercase
+ #FooBar = foo_bar; Foo_Bar = foo_bar; FOOBar = foo_bar; FooBAR = foo_bar
+ my @fragments = map {
+ join("_", split(/(?:(?<=[A-Z])(?=[A-Z][^_A-Z])|(?<=[^_A-Z])(?=[A-Z]))/, $_))
+ } split('::', $last);
+ return lc(join('/', @fragments));
+ };
+
+ implements 'layout_set_file_extension' => as {
+ confess View." is abstract, you must subclass it";
+ };
+
implements 'find_related_class' => as {
my ($self, $rel) = @_;
my $own_class = ref($self) || $self;