« lib/Reaction/UI/ViewPort/Field/TimeRange.pm
↑ Summary
lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm »
| 1 | package Reaction::UI::ViewPort::Collection; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use Reaction::Class; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use aliased 'Reaction::UI::ViewPort::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use MooseX::Types::Moose qw/Str HashRef/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use namespace::clean -except => [ qw(meta) ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | extends 'Reaction::UI::ViewPort'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | with 'Reaction::UI::ViewPort::Collection::Role::Pager'; | |||||||||||||||||||||||||||
| 14 | 5 | with 'Reaction::UI::ViewPort::Role::Actions'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 5 | has members => (is => 'rw', isa => 'ArrayRef', lazy_build => 1); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 5 | has collection => (is => 'ro', isa => IM_Collection, required => 1); | |||||||||||||||||||||||||||
| 19 | 5 | has current_collection => (is => 'rw', isa => IM_Collection, lazy_build => 1); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 5 | has member_args => ( is => 'rw', isa => HashRef, lazy_build => 1); | |||||||||||||||||||||||||||
| 22 | 5 | has member_class => ( is => 'ro', isa => Str, lazy_build => 1); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | if( my $member_args = delete $args->{Member} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | $self->member_args( $member_args ); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub _build_member_args { {} } | ||||||||||||||||||||||||||
|
Subroutine
_build_member_args: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub _build_member_class { Object }; | ||||||||||||||||||||||||||
|
Subroutine
_build_member_class: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | after clear_current_collection => sub{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 36 | 0 | shift->clear_members; #clear the members the current collection changes, duh | |||||||||||||||||||||||||||
| 37 | 5 | }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub _build_current_collection { | ||||||||||||||||||||||||||
|
Subroutine
_build_current_collection: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 40 | 0 | return $_[0]->collection; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | #I'm not really sure why this is here all of a sudden. | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub model { shift->current_collection } | ||||||||||||||||||||||||||
|
Subroutine
model: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub _build_members { | ||||||||||||||||||||||||||
|
Subroutine
_build_members: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | my (@members, $i); | |||||||||||||||||||||||||||
| 49 | 0 | my $args = $self->member_args; | |||||||||||||||||||||||||||
| 50 | 0 | my $builders = {}; | |||||||||||||||||||||||||||
| 51 | 0 | my $field_orders = {}; | |||||||||||||||||||||||||||
| 52 | 0 | my $ctx = $self->ctx; | |||||||||||||||||||||||||||
| 53 | 0 | my $loc = join('-', $self->location, 'member'); | |||||||||||||||||||||||||||
| 54 | 0 | my $class = $self->member_class; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | #replace $i with a real unique identifier so that we don't run a risk of | ||||||||||||||||||||||||||||
| 57 | # events being passed down to the wrong viewport. for now i disabled event | ||||||||||||||||||||||||||||
| 58 | # passing until i fix this (groditi) | ||||||||||||||||||||||||||||
| 59 | 0 | for my $obj ( $self->current_collection->members ) { | |||||||||||||||||||||||||||
| 60 | 0 | my $type = blessed $obj; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $builder_cache = $builders->{$type} ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$builders->{$type} ||= {}
MC/DC0%0/1
$builders->{$type} ||= {}
$builders->{$type}
Truth table0%0/2
A
A= $builders->{$type}
| |||||||||||||||||||||||||||||
| 62 | 0 | my @order; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | if( exists $args->{computed_field_order} ){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 64 | 0 | @order = (computed_field_order => $args->{computed_field_order}); | |||||||||||||||||||||||||||
| 65 | } elsif( exists $field_orders->{$type} ) { | ||||||||||||||||||||||||||||
| 66 | 0 | @order = (computed_field_order => $field_orders->{$type}); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $member = $class->new( | |||||||||||||||||||||||||||
| 70 | ctx => $ctx, | ||||||||||||||||||||||||||||
| 71 | model => $obj, | ||||||||||||||||||||||||||||
| 72 | location => join('-', $loc, $i++), | ||||||||||||||||||||||||||||
| 73 | builder_cache => $builder_cache, | ||||||||||||||||||||||||||||
| 74 | @order, %$args, | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | #cache to prevent the sort function from having to be run potentially | ||||||||||||||||||||||||||||
| 78 | #hundreds of times | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $field_orders->{$type} ||= $member->computed_field_order unless @order; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$field_orders->{$type} ||= $member->computed_field_order
MC/DC0%0/2
$field_orders->{$type} ||= $member->computed_field_order
$field_orders->{$type}
$member->computed_field_order
Truth table0%0/3
A ||= B
A= $field_orders->{$type}B= $member->computed_field_order
| |||||||||||||||||||||||||||||
| 80 | 0 | push(@members, $member); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | return \@members; | |||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 5 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | __END__; | ||||||||||||||||||||||||||||