diff options
author | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-07-24 01:42:34 +0000 |
---|---|---|
committer | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-07-24 01:42:34 +0000 |
commit | 8139388160b0a38002b22ff95c3fee3d8380f156 (patch) | |
tree | d7610c5db84c2c996107adb36bca1fe8a2b0b7cb /lib/Reaction/UI/ViewPort/Field.pm | |
parent | 2a4c89335368295f0fc55f79d2c8fd5e33afd212 (diff) | |
download | reaction-8139388160b0a38002b22ff95c3fee3d8380f156.tar.gz reaction-8139388160b0a38002b22ff95c3fee3d8380f156.zip |
rclass stuff ripped out of everything but widget classes
Diffstat (limited to 'lib/Reaction/UI/ViewPort/Field.pm')
-rw-r--r-- | lib/Reaction/UI/ViewPort/Field.pm | 108 |
1 files changed, 52 insertions, 56 deletions
diff --git a/lib/Reaction/UI/ViewPort/Field.pm b/lib/Reaction/UI/ViewPort/Field.pm index 1ccc99c..a4bb219 100644 --- a/lib/Reaction/UI/ViewPort/Field.pm +++ b/lib/Reaction/UI/ViewPort/Field.pm @@ -4,64 +4,60 @@ use Reaction::Class; use aliased 'Reaction::InterfaceModel::Object'; use aliased 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute'; -class Field is 'Reaction::UI::ViewPort', which { - - has value => (is => 'rw', lazy_build => 1); - has name => (is => 'rw', isa => 'Str', lazy_build => 1); - has label => (is => 'rw', isa => 'Str', lazy_build => 1); - has value_string => (is => 'rw', isa => 'Str', lazy_build => 1); - - has model => (is => 'ro', isa => Object, required => 1); - has attribute => (is => 'ro', isa => ParameterAttribute, required => 1); - - implements _build_name => as { shift->attribute->name }; - - implements _build_label => as { - join(' ', map { ucfirst } split('_', shift->name)); - }; - - implements _build_value => as { - my ($self) = @_; - my $reader = $self->attribute->get_read_method; - return $self->model->$reader; - }; - - implements _model_has_value => as { - my ($self) = @_; - my $predicate = $self->attribute->get_predicate_method; - - if (!$predicate || $self->model->$predicate - #|| ($self->attribute->is_lazy - # && !$self->attribute->is_lazy_fail) - ) { - # either model attribute has a value now or can build it - return 1; - } - return 0; - }; - - implements _build_value_string => as { - my ($self) = @_; - # XXX need the defined test because the IM lazy builds from - # the model and DBIC can have nullable fields and DBIC doesn't - # have a way to tell us that doesn't force value inflation (extra - # SELECTs for belongs_to) so basically we're screwed. - return ($self->_model_has_value && defined($self->_build_value) - ? $self->_value_string_from_value - : $self->_empty_string_value); - }; - - implements _value_string_from_value => as { - shift->value; - }; - - implements _empty_string_value => as { '' }; - - implements value_is_required => as { - shift->attribute->is_required; - }; +use namespace::clean -except => [ qw(meta) ]; +extends 'Reaction::UI::ViewPort'; + + +has value => (is => 'rw', lazy_build => 1); +has name => (is => 'rw', isa => 'Str', lazy_build => 1); +has label => (is => 'rw', isa => 'Str', lazy_build => 1); +has value_string => (is => 'rw', isa => 'Str', lazy_build => 1); + +has model => (is => 'ro', isa => Object, required => 1); +has attribute => (is => 'ro', isa => ParameterAttribute, required => 1); +sub _build_name { shift->attribute->name }; +sub _build_label { + join(' ', map { ucfirst } split('_', shift->name)); +}; +sub _build_value { + my ($self) = @_; + my $reader = $self->attribute->get_read_method; + return $self->model->$reader; +}; +sub _model_has_value { + my ($self) = @_; + my $predicate = $self->attribute->get_predicate_method; + + if (!$predicate || $self->model->$predicate + #|| ($self->attribute->is_lazy + # && !$self->attribute->is_lazy_fail) + ) { + # either model attribute has a value now or can build it + return 1; + } + return 0; }; +sub _build_value_string { + my ($self) = @_; + # XXX need the defined test because the IM lazy builds from + # the model and DBIC can have nullable fields and DBIC doesn't + # have a way to tell us that doesn't force value inflation (extra + # SELECTs for belongs_to) so basically we're screwed. + return ($self->_model_has_value && defined($self->_build_value) + ? $self->_value_string_from_value + : $self->_empty_string_value); +}; +sub _value_string_from_value { + shift->value; +}; +sub _empty_string_value { '' }; +sub value_is_required { + shift->attribute->is_required; +}; + +__PACKAGE__->meta->make_immutable; + 1; __END__; |