1 package Reaction::UI::ViewPort::Role::FieldArgs;
4 use namespace::clean -except => [ qw(meta) ];
6 has field_order => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
7 has excluded_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
8 has included_fields => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1);
9 has computed_field_order => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
11 has _raw_field_labels => (
14 init_arg => 'field_labels',
15 default => sub { {} },
25 sub _build_field_labels {
27 my %labels = %{$self->_raw_field_labels};
28 for my $field ( @{$self->computed_field_order}) {
29 next if defined $labels{$field};
30 $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
35 sub _build_field_order { [] }
37 sub _build_excluded_fields { [] }
39 sub _build_included_fields { [] }
41 #this is a total clusterfuck and it sucks we should just eliminate it and have
42 # the grid members not render ArrayRef or Collection fields
43 sub _build_computed_field_order {
45 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
46 my %included = map { $_ => undef } @{ $self->included_fields };
47 #treat _$field_name as private and exclude fields with no reader
48 my @names = grep { $_ !~ /^_/ && (!%included || exists( $included{$_}) )
49 && !exists($excluded{$_})} map { $_->name }
51 !($_->has_type_constraint &&
52 ($_->type_constraint->is_a_type_of('ArrayRef') ||
53 eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} ||
54 eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') }
57 grep { defined $_->get_read_method }
58 $self->current_collection->member_type->parameter_attributes;
60 return $self->sort_by_spec($self->field_order, \@names);
63 around _build_members => sub {
66 $self->member_args->{computed_field_order} ||= $self->computed_field_order;
67 my $members = $self->$orig(@_);
78 Reaction::UI::ViewPort::Role::FieldOptions
86 =head2 excluded_fields
88 List of field names to exclude.
90 =head2 included_fields
92 List of field names to include. If both C<included_fields> and
93 C<excluded_fields> are specified the result is those fields which
94 are in C<included_fields> and not in C<excluded_fields>.
96 =head2 included_fields
98 List of field names to include. If both C<included_fields> and
99 C<excluded_fields> are specified the result is those fields which
100 are in C<included_fields> and not in C<excluded_fields>.
104 =head2 computed_field_order
106 =head1 INTERNAL METHODS
108 These methods, although stable, are subject to change without notice. These are meant
109 to be used only by developers. End users should refrain from using these methods to
110 avoid potential breakages.
114 L<Reaction::UI::ViewPort::Collection>
118 See L<Reaction::Class> for authors.
122 See L<Reaction::Class> for the license.