aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/View.pm
diff options
context:
space:
mode:
authorgroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-04-26 20:04:50 +0000
committergroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-04-26 20:04:50 +0000
commitc4481e7345f7dfe83ca4503af94f33928f973e70 (patch)
tree710036ecc510397af3a700ef4f0816bf87294a06 /lib/Reaction/UI/View.pm
parentdb430ae8eb228482cbee8cc3c8a04c3aac30d606 (diff)
downloadreaction-c4481e7345f7dfe83ca4503af94f33928f973e70.tar.gz
reaction-c4481e7345f7dfe83ca4503af94f33928f973e70.zip
made layoutset name generation smarter, basic tests for name generation
Diffstat (limited to 'lib/Reaction/UI/View.pm')
-rw-r--r--lib/Reaction/UI/View.pm24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/Reaction/UI/View.pm b/lib/Reaction/UI/View.pm
index 358fcf1..f0767f2 100644
--- a/lib/Reaction/UI/View.pm
+++ b/lib/Reaction/UI/View.pm
@@ -78,21 +78,27 @@ class View which {
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";
};