| 1 | package Gapp::Layout::Object; | ||||||||||||||||||||
| 2 | { | ||||||||||||||||||||
| 3 | 1 | $Gapp::Layout::Object::VERSION = '0.60'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | use MooseX::Types::Moose qw( :all ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | has 'parent' => ( | |||||||||||||||||||
| 13 | is => 'rw', | ||||||||||||||||||||
| 14 | isa => Object, | ||||||||||||||||||||
| 15 | weak_ref => 1, | ||||||||||||||||||||
| 16 | predicate => 'has_parent', | ||||||||||||||||||||
| 17 | clearer => 'clear_parent', | ||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | has '_builders' => ( | ||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||
| 22 | isa => HashRef, | ||||||||||||||||||||
| 23 | 3 | ▶ | default => sub { { } }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 1 | init_arg => undef, | |||||||||||||||||||
| 25 | traits => [qw( Hash )], | ||||||||||||||||||||
| 26 | handles => { | ||||||||||||||||||||
| 27 | add_builder => 'set', | ||||||||||||||||||||
| 28 | get_builder => 'get', | ||||||||||||||||||||
| 29 | has_builder => 'exists', | ||||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | has '_stylers' => ( | ||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||
| 35 | isa => HashRef, | ||||||||||||||||||||
| 36 | 3 | ▶ | default => sub { { } }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | 1 | init_arg => undef, | |||||||||||||||||||
| 38 | traits => [qw( Hash )], | ||||||||||||||||||||
| 39 | handles => { | ||||||||||||||||||||
| 40 | add_styler => 'set', | ||||||||||||||||||||
| 41 | get_styler => 'get', | ||||||||||||||||||||
| 42 | has_styler => 'exists', | ||||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | has '_painters' => ( | ||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||
| 48 | isa => HashRef, | ||||||||||||||||||||
| 49 | 3 | ▶ | default => sub { { } }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 50 | 1 | init_arg => undef, | |||||||||||||||||||
| 51 | traits => [qw( Hash )], | ||||||||||||||||||||
| 52 | handles => { | ||||||||||||||||||||
| 53 | add_painter => 'set', | ||||||||||||||||||||
| 54 | get_painter => 'get', | ||||||||||||||||||||
| 55 | has_painter => 'exists', | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | has '_packers' => ( | ||||||||||||||||||||
| 60 | is => 'ro', | ||||||||||||||||||||
| 61 | isa => 'HashRef[HashRef]', | ||||||||||||||||||||
| 62 | 3 | ▶ | default => sub { { } }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 63 | 1 | init_arg => undef, | |||||||||||||||||||
| 64 | traits => [ 'Hash' ], | ||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # the "packer" is a code ref that is called to | ||||||||||||||||||||
| 68 | # add a widget to a container | ||||||||||||||||||||
| 69 | 20 | ▶ | sub add_packer { | ||||||||||||||||||
|
Subroutine
add_packer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 70 | 20 | my ( $self, $widget, $container, $code_ref ) = @_; | |||||||||||||||||||
| 71 | 20 | $self->_packers->{$widget}{$container} = $code_ref; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | ▶ | sub build_widget { | ||||||||||||||||||
|
Subroutine
build_widget: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 75 | 0 | my ( $self, $widget, $opts ) = @_; | |||||||||||||||||||
| 76 | 0 | my $builder = $self->find_builder( $widget ); | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | ▶ | return if ! $builder; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | $builder->( $self, $widget ); | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | # search this layout and parent layouts for a builder that will DWIM | ||||||||||||||||||||
| 87 | 0 | ▶ | sub find_builder { | ||||||||||||||||||
|
Subroutine
find_builder: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 88 | 0 | my ( $self, $w, $opts ) = @_; | |||||||||||||||||||
| 89 | 0 | ▶ | $w = $w->meta->name if ref $w; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | # work around for dealing with classes that have traits applied | ||||||||||||||||||||
| 92 | 0 | ▶ | if ( $w =~ /__ANON__/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 0 | my ( $super ) = ( $w->meta->superclasses )[0]; | |||||||||||||||||||
| 94 | 0 | $w = $super->meta->name; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | # widget superclasses ( minus Moose stuff ) | ||||||||||||||||||||
| 98 | 0 | my @wisa = $w->meta->linearized_isa; | |||||||||||||||||||
| 99 | 0 | splice @wisa,-1,1; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | for my $wclass ( @wisa ) { | |||||||||||||||||||
| 102 | 0 | my $builder = $self->lookup_builder( $wclass ); | |||||||||||||||||||
| 103 | 0 | ▶ | return $builder if $builder; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | #sub find_builder { | ||||||||||||||||||||
| 108 | # my ( $self, $w ) = @_; | ||||||||||||||||||||
| 109 | # $w = $w->meta->name if ref $w; | ||||||||||||||||||||
| 110 | # $w = ($w->meta->superclasses)[0]->meta->name if $w->meta->name =~ /__ANON__/; | ||||||||||||||||||||
| 111 | # return $self->get_builder( $w->meta->name ) if $self->get_builder( $w->meta->name ); | ||||||||||||||||||||
| 112 | # return $self->parent ? $self->parent->find_builder( $w ) : undef; | ||||||||||||||||||||
| 113 | #} | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | # search this layout and parent layouts for a packer that will DWIM | ||||||||||||||||||||
| 117 | 0 | ▶ | sub find_packer { | ||||||||||||||||||
|
Subroutine
find_packer: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 118 | 0 | my ( $self, $widget, $container ) = @_; | |||||||||||||||||||
| 119 | 0 | ▶ | $widget = $widget->meta->name if ref $widget; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | 0 | ▶ | $container = $container->meta->name if ref $container; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | # work around for dealing with classes that have traits applied | ||||||||||||||||||||
| 123 | 0 | ▶ | if ( $widget->meta->name =~ /__ANON__/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | 0 | my ( $super ) = ( $widget->meta->superclasses )[0]; | |||||||||||||||||||
| 125 | 0 | $widget = $super->meta->name; | |||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | 0 | ▶ | if ( $container->meta->name =~ /__ANON__/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 128 | 0 | my ( $super ) = ( $container->meta->superclasses ); | |||||||||||||||||||
| 129 | 0 | $container = $super->meta->name; | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | # widget superclasses ( minus Moose stuff ) | ||||||||||||||||||||
| 133 | 0 | my @wisa = $widget->meta->linearized_isa; | |||||||||||||||||||
| 134 | 0 | splice @wisa,-1,1; | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | # container superclasses ( minus Moose stuff, minus non-container classes ) | ||||||||||||||||||||
| 138 | 0 | my @cisa = $container->meta->linearized_isa; | |||||||||||||||||||
| 139 | 0 | splice @cisa,-1,1; | |||||||||||||||||||
| 140 | 0 | @cisa = grep { $_->isa('Gapp::Container') } @cisa; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 0 | for my $cclass ( @cisa ) { | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | for my $wclass ( @wisa ) { | |||||||||||||||||||
| 145 | 0 | my $packer = $self->lookup_packer( $wclass, $cclass ); | |||||||||||||||||||
| 146 | 0 | ▶ | return $packer if $packer; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 0 | ▶ | sub find_painter { | ||||||||||||||||||
|
Subroutine
find_painter: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 153 | 0 | my ( $self, $w ) = @_; | |||||||||||||||||||
| 154 | 0 | ▶ | $w = $w->meta->name if ref $w; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 0 | ▶ | $w = ($w->meta->superclasses)[0]->meta->name if $w =~ /__ANON__/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | 0 | ▶ | return $self->get_painter( $w->meta->name ) if $self->get_painter( $w->meta->name ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 0 | ▶ | return $self->parent ? $self->parent->find_painter( $w ) : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | # search this layout and parent layouts for a builder that will DWIM | ||||||||||||||||||||
| 162 | 0 | ▶ | sub find_styler { | ||||||||||||||||||
|
Subroutine
find_styler: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 163 | 0 | my ( $self, $w, $opts ) = @_; | |||||||||||||||||||
| 164 | 0 | ▶ | $w = $w->meta->name if ref $w; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | # work around for dealing with classes that have traits applied | ||||||||||||||||||||
| 167 | 0 | ▶ | if ( $w =~ /__ANON__/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 168 | 0 | my ( $super ) = ( $w->meta->superclasses )[0]; | |||||||||||||||||||
| 169 | 0 | $w = $super->meta->name; | |||||||||||||||||||
| 170 | } | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | # widget superclasses ( minus Moose stuff ) | ||||||||||||||||||||
| 173 | 0 | my @wisa = $w->meta->linearized_isa; | |||||||||||||||||||
| 174 | 0 | splice @wisa,-1,1; | |||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | 0 | for my $wclass ( @wisa ) { | |||||||||||||||||||
| 177 | 0 | my $styler = $self->lookup_styler( $wclass ); | |||||||||||||||||||
| 178 | 0 | ▶ | return $styler if $styler; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 179 | } | ||||||||||||||||||||
| 180 | } | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | 3 | ▶ | sub get_packer { | ||||||||||||||||||
|
Subroutine
get_packer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 184 | 3 | my ( $self, $widget, $container ) = @_; | |||||||||||||||||||
| 185 | 3 | $self->_packers->{$widget}{$container}; | |||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | 1 | ▶ | sub has_packer { | ||||||||||||||||||
|
Subroutine
has_packer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 189 | 1 | my ( $self, $widget, $container ) = @_; | |||||||||||||||||||
| 190 | 1 | exists $self->_packers->{$widget}{$container}; | |||||||||||||||||||
| 191 | } | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 0 | ▶ | sub lookup_builder { | ||||||||||||||||||
|
Subroutine
lookup_builder: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 195 | 0 | my ( $self, $w ) = @_; | |||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | 0 | ▶ | if ( $self->has_builder( $w ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 198 | 0 | return $self->get_builder( $w ); | |||||||||||||||||||
| 199 | } | ||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||
| 201 | 0 | ▶ | return $self->parent ? | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 202 | $self->parent->lookup_builder( $w ) : | ||||||||||||||||||||
| 203 | undef; | ||||||||||||||||||||
| 204 | } | ||||||||||||||||||||
| 205 | } | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | # search this layout and parent layouts for specific packer | ||||||||||||||||||||
| 208 | 0 | ▶ | sub lookup_packer { | ||||||||||||||||||
|
Subroutine
lookup_packer: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 209 | 0 | my ( $self, $widget, $container ) = @_; | |||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | 0 | ▶ | if ( $self->has_packer( $widget, $container ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 212 | 0 | return $self->get_packer( $widget, $container ); | |||||||||||||||||||
| 213 | } | ||||||||||||||||||||
| 214 | else { | ||||||||||||||||||||
| 215 | 0 | ▶ | return $self->parent ? | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 216 | $self->parent->lookup_packer( $widget, $container ) : | ||||||||||||||||||||
| 217 | undef; | ||||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | } | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | 0 | ▶ | sub lookup_styler { | ||||||||||||||||||
|
Subroutine
lookup_styler: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 222 | 0 | my ( $self, $w ) = @_; | |||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | 0 | ▶ | if ( $self->has_styler( $w ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 225 | 0 | return $self->get_styler( $w ); | |||||||||||||||||||
| 226 | } | ||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||
| 228 | 0 | ▶ | return $self->parent ? | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 229 | $self->parent->lookup_styler( $w ) : | ||||||||||||||||||||
| 230 | undef; | ||||||||||||||||||||
| 231 | } | ||||||||||||||||||||
| 232 | } | ||||||||||||||||||||
| 233 | |||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | # pack a widget inside a container | ||||||||||||||||||||
| 238 | 0 | ▶ | sub pack_widget { | ||||||||||||||||||
|
Subroutine
pack_widget: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 239 | 0 | my ( $self, $widget, $container ) = @_; | |||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | 0 | my $packer = $self->find_packer( $widget , $container ); | |||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | # warn if cannot find packer | ||||||||||||||||||||
| 244 | 0 | ▶ | if ( ! $packer ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 245 | 0 | warn | |||||||||||||||||||
| 246 | qq[could not pack ] . $widget->meta->name . | ||||||||||||||||||||
| 247 | qq[ into ] . $container->meta->name . qq[: ] . | ||||||||||||||||||||
| 248 | qq[no packer found in ] .$self->meta->name; | ||||||||||||||||||||
| 249 | 0 | return; | |||||||||||||||||||
| 250 | } | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | # pack the widget | ||||||||||||||||||||
| 253 | 0 | $packer->( $self, $widget, $container ); | |||||||||||||||||||
| 254 | } | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | 0 | ▶ | sub paint_widget { | ||||||||||||||||||
|
Subroutine
paint_widget: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 257 | 0 | my ( $self, $widget, $opts ) = @_; | |||||||||||||||||||
| 258 | 0 | ▶ | my $painter = $self->find_painter( $opts->{as} || $widget ); | ||||||||||||||||||
|
Condition0%0/3
$opts->{'as'} || $widget
MC/DC0%0/2
$opts->{'as'} || $widget
$opts->{'as'}
$widget
Truth table0%0/3
A || B
A= $opts->{'as'}B= $widget
| |||||||||||||||||||||
| 259 | 0 | ▶ | return if ! $painter; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | 0 | $painter->( $self, $widget ); | |||||||||||||||||||
| 262 | } | ||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | 0 | ▶ | sub style_widget { | ||||||||||||||||||
|
Subroutine
style_widget: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 265 | 0 | my ( $self, $widget, $opts ) = @_; | |||||||||||||||||||
| 266 | 0 | ▶ | my $builder = $self->find_styler( $opts->{as} || $widget ); | ||||||||||||||||||
|
Condition0%0/3
$opts->{'as'} || $widget
MC/DC0%0/2
$opts->{'as'} || $widget
$opts->{'as'}
$widget
Truth table0%0/3
A || B
A= $opts->{'as'}B= $widget
| |||||||||||||||||||||
| 267 | 0 | ▶ | return if ! $builder; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | 0 | $builder->( $self, $widget ); | |||||||||||||||||||
| 270 | } | ||||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | |||||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | 1 | ▶ | no Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 275 | 1 | __PACKAGE__->meta()->make_immutable(); | |||||||||||||||||||
| 276 | 1 | 1; | |||||||||||||||||||