X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FViewPort%2FCollection%2FGrid.pm;h=42d69f775aca5e5d525a37e3c1318944579f5334;hb=52f292b24eca44347e5f1bfcffe4cedf5465766b;hp=916df3d209477d120647c27ac3a15ed92960f1d4;hpb=92cefe98813d862c46f07d3dc5b3011d96ffbc46;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/ViewPort/Collection/Grid.pm b/lib/Reaction/UI/ViewPort/Collection/Grid.pm index 916df3d..42d69f7 100644 --- a/lib/Reaction/UI/ViewPort/Collection/Grid.pm +++ b/lib/Reaction/UI/ViewPort/Collection/Grid.pm @@ -5,56 +5,55 @@ use Reaction::Class; use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection'; use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member'; -class Grid is 'Reaction::UI::ViewPort::Collection', which { - - has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1); - has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1); - has field_labels => ( is => 'ro', isa => 'HashRef', lazy_build => 1); - - has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1); - - #################################### - implements _build_member_class => as { Member }; - - implements _build_field_labels => as { - my $self = shift; - my %labels; - for my $field ( @{$self->computed_field_order}){ - $labels{$field} = join(' ', map{ ucfirst } split('_', $field)); - } - return \%labels; - }; - - implements _build_field_order => as { []; }; - implements _build_excluded_fields => as { []; }; - - implements _build_computed_field_order => as { - my ($self) = @_; - confess("current_collection lacks a value for 'member_type' attribute") - unless $self->current_collection->has_member_type; - my %excluded = map { $_ => undef } @{ $self->excluded_fields }; - #treat _$field_name as private and exclude fields with no reader - my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name } - grep { - !($_->has_type_constraint && - ($_->type_constraint->is_a_type_of('ArrayRef') || - eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} || - eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') } - ) - ) } - grep { defined $_->get_read_method } - $self->current_collection->member_type->meta->parameter_attributes; - - return $self->sort_by_spec($self->field_order, \@names); - }; - - before _build_members => sub { - my ($self) = @_; - $self->member_args->{computed_field_order} ||= $self->computed_field_order; - }; +use namespace::clean -except => [ qw(meta) ]; +extends 'Reaction::UI::ViewPort::Collection'; + + +has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1); +has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1); +has field_labels => ( is => 'ro', isa => 'HashRef', lazy_build => 1); + +has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1); + +#################################### +sub _build_member_class { Member }; +sub _build_field_labels { + my $self = shift; + my %labels; + for my $field ( @{$self->computed_field_order}){ + $labels{$field} = join(' ', map{ ucfirst } split('_', $field)); + } + return \%labels; +}; +sub _build_field_order { []; }; +sub _build_excluded_fields { []; }; +sub _build_computed_field_order { + my ($self) = @_; + my %excluded = map { $_ => undef } @{ $self->excluded_fields }; + #treat _$field_name as private and exclude fields with no reader + my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name } + grep { + !($_->has_type_constraint && + ($_->type_constraint->is_a_type_of('ArrayRef') || + eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} || + eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') } + ) + ) } + grep { defined $_->get_read_method } + $self->current_collection->member_type->parameter_attributes; + + return $self->sort_by_spec($self->field_order, \@names); }; +before _build_members => sub { + my ($self) = @_; + $self->member_args->{computed_field_order} ||= $self->computed_field_order; +}; + +__PACKAGE__->meta->make_immutable; + + 1; __END__;