« lib/Reaction/InterfaceModel/Action/DBIC/Result/Update.pm
↑ Summary
lib/Reaction/UI/Widget/Container.pm »
| 1 | package Reaction::UI::View; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 5 | ▶ | use Reaction::Class; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | # declaring dependencies | ||||||||||||||||||||
| 6 | 5 | ▶ | use Reaction::UI::LayoutSet; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 5 | ▶ | use Reaction::UI::RenderingContext; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 5 | ▶ | use aliased 'Reaction::UI::Skin'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 5 | ▶ | use aliased 'Path::Class::Dir'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 5 | ▶ | use namespace::clean -except => [ qw(meta) ]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 3 | ▶ | has '_widget_cache' => (is => 'ro', default => sub { {} }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 3 | ▶ | has '_layout_set_cache' => (is => 'ro', default => sub { {} }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 5 | has 'app' => (is => 'ro', required => 1); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 5 | has 'skin_name' => (is => 'ro', required => 1, default => 'default'); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 5 | has 'skin' => ( | |||||||||||||||||||
| 23 | is => 'ro', lazy_build => 1, | ||||||||||||||||||||
| 24 | handles => [ qw(create_layout_set search_path_for_type) ] | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 5 | has 'layout_set_class' => (is => 'ro', lazy_build => 1); | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 5 | has 'rendering_context_class' => (is => 'ro', lazy_build => 1); | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # default view doesn't localize | ||||||||||||||||||||
| 32 | 21 | ▶ | sub localize { | ||||||||||||||||||
|
Subroutine
localize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 33 | 21 | my($self, $value) = @_; | |||||||||||||||||||
| 34 | 21 | return $value; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 2 | ▶ | sub _build_layout_set_class { | ||||||||||||||||||
|
Subroutine
_build_layout_set_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | 2 | my ($self) = @_; | |||||||||||||||||||
| 39 | 2 | return $self->find_related_class('LayoutSet'); | |||||||||||||||||||
| 40 | }; | ||||||||||||||||||||
| 41 | 2 | ▶ | sub _build_rendering_context_class { | ||||||||||||||||||
|
Subroutine
_build_rendering_context_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | 2 | my ($self) = @_; | |||||||||||||||||||
| 43 | 2 | return $self->find_related_class('RenderingContext'); | |||||||||||||||||||
| 44 | }; | ||||||||||||||||||||
| 45 | 2 | ▶ | sub _build_skin { | ||||||||||||||||||
|
Subroutine
_build_skin: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | 2 | my ($self) = @_; | |||||||||||||||||||
| 47 | 2 | Skin->new( | |||||||||||||||||||
| 48 | name => $self->skin_name, view => $self, | ||||||||||||||||||||
| 49 | # path_to returns a File, not a Dir. Thanks, Catalyst. | ||||||||||||||||||||
| 50 | skin_base_dir => Dir->new($self->app->path_to('share', 'skin')), | ||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||
| 53 | 3 | ▶ | sub COMPONENT { | ||||||||||||||||||
|
Subroutine
COMPONENT: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 54 | 3 | my ($class, $app, $args) = @_; | |||||||||||||||||||
| 55 | 3 | ▶ | return $class->new(%{$args||{}}, app => $app); | ||||||||||||||||||
|
Condition50%1/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||
| 56 | }; | ||||||||||||||||||||
| 57 | 4 | ▶ | sub render_window { | ||||||||||||||||||
|
Subroutine
render_window: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 58 | 4 | my ($self, $window) = @_; | |||||||||||||||||||
| 59 | 4 | my $root_vp = $window->focus_stack->vp_head; | |||||||||||||||||||
| 60 | 4 | my $rctx = $self->create_rendering_context; | |||||||||||||||||||
| 61 | 4 | my ($widget, $args) = $self->render_viewport_args($root_vp); | |||||||||||||||||||
| 62 | 4 | $widget->render(widget => $rctx, $args); | |||||||||||||||||||
| 63 | }; | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | # From 2007-07-11 @ #reaction (so don't blame me if you think this violates some stupid school of thought) | ||||||||||||||||||||
| 66 | #15:09 <@groditi> mst: one quick thing though. do you remember what layout_args is? | ||||||||||||||||||||
| 67 | #15:10 <@mst> isn't it crap to be passed to the top level widget render? | ||||||||||||||||||||
| 68 | #15:11 <@groditi> that's what i thought.. | ||||||||||||||||||||
| 69 | #15:11 <@groditi> but it's kind of a no-op. there's an attr but nothing uses it | ||||||||||||||||||||
| 70 | #15:11 <@groditi> i cant figure out if the data you give it ends up going anywhere | ||||||||||||||||||||
| 71 | #15:12 <@groditi> although it'd be cool if anything you put there ended up being part of %_ in layout/widget land | ||||||||||||||||||||
| 72 | #15:12 <@groditi> which would solve so fucking many of my gripes with widget/layout | ||||||||||||||||||||
| 73 | #15:14 <@mst> I thought that was what it was supposed to do | ||||||||||||||||||||
| 74 | #15:14 <@mst> wire it up :) | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 23 | ▶ | sub render_viewport_args { | ||||||||||||||||||
|
Subroutine
render_viewport_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 77 | 23 | my ($self, $vp) = @_; | |||||||||||||||||||
| 78 | 23 | my $layout_set = $self->layout_set_for($vp); | |||||||||||||||||||
| 79 | 23 | my $widget = $self->widget_for($vp, $layout_set); | |||||||||||||||||||
| 80 | 23 | my %layout_args = (%{ $vp->layout_args }, viewport => $vp); | |||||||||||||||||||
| 81 | 23 | return ($widget, \%layout_args); | |||||||||||||||||||
| 82 | }; | ||||||||||||||||||||
| 83 | 23 | ▶ | sub widget_for { | ||||||||||||||||||
|
Subroutine
widget_for: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 84 | 23 | my ($self, $vp, $layout_set) = @_; | |||||||||||||||||||
| 85 | return | ||||||||||||||||||||
| 86 | 23 | ▶ | $self->_widget_cache->{$layout_set->name} | ||||||||||||||||||
|
Condition66%2/3
$self->_widget_cache->{$layout_set->name} ||= $layout_set->widget_class->new("view", $self, "layout_set", $layout_set)
MC/DC0%0/2
$self->_widget_cache->{$layout_set->name} ||= $layout_set->widget_class->new("view", $self, "layout_set", $layout_set)
$self->_widget_cache->{$layout_set->name}
$layout_set->widget_class->new("view", $self, "layout_set", $layout_set)
Truth table66%2/3
A ||= B
A= $self->_widget_cache->{$layout_set->name}B= $layout_set->widget_class->new("view", $self, "layout_set", $layout_set)
| |||||||||||||||||||||
| 87 | ||= $layout_set->widget_class | ||||||||||||||||||||
| 88 | ->new( | ||||||||||||||||||||
| 89 | view => $self, layout_set => $layout_set | ||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||
| 92 | 23 | ▶ | sub layout_set_for { | ||||||||||||||||||
|
Subroutine
layout_set_for: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||
| 93 | 23 | my ($self, $vp) = @_; | |||||||||||||||||||
| 94 | 23 | my $lset_name = eval { $vp->layout }; | |||||||||||||||||||
| 95 | 23 | ▶ | confess "Couldn't call layout method on \$vp arg ${vp}: $@" if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 23 | ▶ | $lset_name = $self->layout_set_name_from_viewport( blessed($vp) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | unless (length($lset_name)); | ||||||||||||||||||||
| 98 | 23 | my $cache = $self->_layout_set_cache; | |||||||||||||||||||
| 99 | 23 | ▶ | return $cache->{$lset_name} ||= $self->create_layout_set($lset_name); | ||||||||||||||||||
|
Condition66%2/3
$cache->{$lset_name} ||= $self->create_layout_set($lset_name)
MC/DC0%0/2
$cache->{$lset_name} ||= $self->create_layout_set($lset_name)
$cache->{$lset_name}
$self->create_layout_set($lset_name)
Truth table66%2/3
A ||= B
A= $cache->{$lset_name}B= $self->create_layout_set($lset_name)
| |||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | #XXX if it ever comes to it: this could be memoized. not bothering yet. | ||||||||||||||||||||
| 103 | 26 | ▶ | sub layout_set_name_from_viewport { | ||||||||||||||||||
|
Subroutine
layout_set_name_from_viewport: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 104 | 26 | my ($self, $class) = @_; | |||||||||||||||||||
| 105 | 26 | my ($last) = ($class =~ /.*(?:::ViewPort::)(.+?)$/); | |||||||||||||||||||
| 106 | #split when a non-uppercase letter meets an uppercase or when an | ||||||||||||||||||||
| 107 | #uppercase letter is followed by another uppercase and then a non-uppercase | ||||||||||||||||||||
| 108 | #FooBar = foo_bar; Foo_Bar = foo_bar; FOOBar = foo_bar; FooBAR = foo_bar | ||||||||||||||||||||
| 109 | my @fragments = map { | ||||||||||||||||||||
| 110 | 26 | join("_", split(/(?:(?<=[A-Z])(?=[A-Z][^_A-Z])|(?<=[^_A-Z])(?=[A-Z]))/, $_)) | |||||||||||||||||||
| 111 | } split('::', $last); | ||||||||||||||||||||
| 112 | 26 | return lc(join('/', @fragments)); | |||||||||||||||||||
| 113 | }; | ||||||||||||||||||||
| 114 | 0 | ▶ | sub layout_set_file_extension { | ||||||||||||||||||
|
Subroutine
layout_set_file_extension: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 115 | 0 | confess View." is abstract, you must subclass it"; | |||||||||||||||||||
| 116 | }; | ||||||||||||||||||||
| 117 | 4 | ▶ | sub find_related_class { | ||||||||||||||||||
|
Subroutine
find_related_class: called CC=7 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||
| 118 | 4 | my ($self, $rel) = @_; | |||||||||||||||||||
| 119 | 4 | ▶ | my $own_class = ref($self) || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 120 | 4 | ▶ | confess View." is abstract, you must subclass it" if $own_class eq View; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | 4 | foreach my $super ($own_class->meta->class_precedence_list) { | |||||||||||||||||||
| 122 | 8 | ▶ | next if $super eq View; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | 8 | ▶ | if ($super =~ /::View::/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | 8 | (my $class = $super) =~ s/::View::/::${rel}::/; | |||||||||||||||||||
| 125 | 8 | ▶ | if (eval { Class::MOP::load_class($class) }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | 4 | return $class; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | 0 | confess "Unable to find related ${rel} class for ${own_class}"; | |||||||||||||||||||
| 131 | }; | ||||||||||||||||||||
| 132 | 4 | ▶ | sub create_rendering_context { | ||||||||||||||||||
|
Subroutine
create_rendering_context: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 133 | 4 | my ($self, @args) = @_; | |||||||||||||||||||
| 134 | 4 | return $self->rendering_context_class->new( | |||||||||||||||||||
| 135 | $self->rendering_context_args_for(@args), | ||||||||||||||||||||
| 136 | @args, | ||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||
| 139 | 4 | ▶ | sub rendering_context_args_for { | ||||||||||||||||||
|
Subroutine
rendering_context_args_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 140 | 4 | return (); | |||||||||||||||||||
| 141 | }; | ||||||||||||||||||||
| 142 | 22 | ▶ | sub layout_set_args_for { | ||||||||||||||||||
|
Subroutine
layout_set_args_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 143 | 22 | return (); | |||||||||||||||||||
| 144 | }; | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =pod | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =head1 NAME | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | Reaction::UI::View - Render the UI. | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | =head1 SYNOPSIS | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | package MyApp::View::TT; | ||||||||||||||||||||
| 157 | use base 'Reaction::UI::View::TT'; | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | __PACKAGE__->config( | ||||||||||||||||||||
| 160 | skin_name => 'MyApp', | ||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | ## In the Window class: | ||||||||||||||||||||
| 164 | $res->body($self->view->render_window($self)); | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =head1 DESCRIPTION | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | Render the viewports in the current window using the chosen skin and | ||||||||||||||||||||
| 169 | layoutset, via the matching widgets. | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | See also: | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =over | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | =item L<Reaction::UI::Controller::Root> | ||||||||||||||||||||
| 176 | =item L<Reaction::UI::ViewPort> | ||||||||||||||||||||
| 177 | =item L<Reaction::UI::Window> | ||||||||||||||||||||
| 178 | =item L<Reaction::UI::LayoutSet> | ||||||||||||||||||||
| 179 | =item L<Reaction::UI::Widget> | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | =back | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | =head2 app | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | =over | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | =item Arguments: $app? | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | =back | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | The application L<Catalyst> class. This is set at | ||||||||||||||||||||
| 194 | L<Catalyst/COMPONENT> time for you. | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | =head2 skin_name | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | =over | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | =item Arguments: $skinname? | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | =back | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | The name of the skin to use to render the pages. This should be the | ||||||||||||||||||||
| 205 | name of a subdirectory under the F<share/skin> in your application | ||||||||||||||||||||
| 206 | directory. The default skin name is C<default>, the default skin is | ||||||||||||||||||||
| 207 | provided with Reaction. | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | See also: L<Reaction::UI::Skin> | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | =head2 skin | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | =over | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | =item Arguments: $skin? | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | =back | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | A L<Reaction::UI::Skin> object based on the L</skin_name>. It will be | ||||||||||||||||||||
| 220 | created for you if not provided. | ||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | =head2 layout_set_class | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | The class of the L<Reaction::UI::LayoutSet> used to layout the | ||||||||||||||||||||
| 225 | view. Defaults to searching down the precedence tree of the View class | ||||||||||||||||||||
| 226 | looking for a class of the same name with C<View> replaced with | ||||||||||||||||||||
| 227 | C<LayoutSet>. | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | =head2 rendering_context_class | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | The class of the L<Reaction::UI::RenderingContext> used to layout the | ||||||||||||||||||||
| 232 | view. Defaults to searching down the precedence tree of the View class | ||||||||||||||||||||
| 233 | looking for a class of the same name with C<View> replaced with | ||||||||||||||||||||
| 234 | C<RenderingContext>. | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | =head1 METHODS | ||||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | =head1 AUTHORS | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | See L<Reaction::Class> for authors. | ||||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | =head1 LICENSE | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | See L<Reaction::Class> for the license. | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | =cut | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | 5 | 1; | |||||||||||||||||||