| 1 | package Reaction::UI::ViewPort::Field; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use Reaction::Class; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use aliased 'Reaction::InterfaceModel::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use aliased 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use MooseX::Types::Moose qw/Str/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use namespace::clean -except => [ qw(meta) ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | extends 'Reaction::UI::ViewPort'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 5 | has value => (is => 'rw', lazy_build => 1); | |||||||||||||||||||||||||||
| 13 | 5 | has name => (is => 'rw', isa => Str, lazy_build => 1); | |||||||||||||||||||||||||||
| 14 | 5 | has label => (is => 'rw', isa => Str, lazy_build => 1); | |||||||||||||||||||||||||||
| 15 | 5 | has value_string => (is => 'rw', isa => Str, lazy_build => 1); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 5 | has model => (is => 'ro', isa => Object, required => 1); | |||||||||||||||||||||||||||
| 18 | 5 | has attribute => (is => 'ro', isa => ParameterAttribute, required => 1); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 12 | ▶ | sub _build_name { shift->attribute->name }; | ||||||||||||||||||||||||||
|
Subroutine
_build_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 12 | ▶ | sub _build_label { | ||||||||||||||||||||||||||
|
Subroutine
_build_label: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 12 | join(' ', map { ucfirst } split('_', shift->name)); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 18 | ▶ | sub _build_value { | ||||||||||||||||||||||||||
|
Subroutine
_build_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||
| 28 | 18 | my $reader = $self->attribute->get_read_method; | |||||||||||||||||||||||||||
| 29 | 18 | return $self->model->$reader; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1215 | ▶ | sub _model_has_value { | ||||||||||||||||||||||||||
|
Subroutine
_model_has_value: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 33 | 1215 | my ($self) = @_; | |||||||||||||||||||||||||||
| 34 | 1215 | my $predicate = $self->attribute->get_predicate_method; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1215 | ▶ | if (!$predicate || $self->model->$predicate | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $predicate or $self->model->$predicate
MC/DC50%1/2
not $predicate or $self->model->$predicate
not $predicate
$self->model->$predicate
Truth table66%2/3
not(A) or B
A= not $predicateB= $self->model->$predicate
| |||||||||||||||||||||||||||||
| 37 | # || ($self->attribute->is_lazy | ||||||||||||||||||||||||||||
| 38 | # && !$self->attribute->is_lazy_fail) | ||||||||||||||||||||||||||||
| 39 | ) { | ||||||||||||||||||||||||||||
| 40 | # edenc -- uncommented the lazy checks above | ||||||||||||||||||||||||||||
| 41 | # model->$predicate returns false if the value isn't set | ||||||||||||||||||||||||||||
| 42 | # but has a lazy builder | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # either model attribute has a value now or can build it | ||||||||||||||||||||||||||||
| 45 | 1211 | return 1; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 4 | return 0; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 12 | ▶ | sub _build_value_string { | ||||||||||||||||||||||||||
|
Subroutine
_build_value_string: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 51 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||
| 52 | # XXX need the defined test because the IM lazy builds from | ||||||||||||||||||||||||||||
| 53 | # the model and DBIC can have nullable fields and DBIC doesn't | ||||||||||||||||||||||||||||
| 54 | # have a way to tell us that doesn't force value inflation (extra | ||||||||||||||||||||||||||||
| 55 | # SELECTs for belongs_to) so basically we're screwed. | ||||||||||||||||||||||||||||
| 56 | 12 | ▶ | return ($self->_model_has_value && defined($self->_build_value) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_model_has_value and defined $self->_build_value
MC/DC50%1/2
$self->_model_has_value and defined $self->_build_value
$self->_model_has_value
defined $self->_build_value
Truth table66%2/3
A and B
A= $self->_model_has_valueB= defined $self->_build_value
| |||||||||||||||||||||||||||||
| 57 | ? $self->_value_string_from_value | ||||||||||||||||||||||||||||
| 58 | : $self->_empty_string_value); | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 7 | ▶ | sub _value_string_from_value { | ||||||||||||||||||||||||||
|
Subroutine
_value_string_from_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 7 | shift->value; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub _empty_string_value { '' } | ||||||||||||||||||||||||||
|
Subroutine
_empty_string_value: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 9 | ▶ | sub value_is_required { | ||||||||||||||||||||||||||
|
Subroutine
value_is_required: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | 9 | $self->model->attribute_is_required($self->attribute); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | 1; | |||||||||||||||||||||||||||
| 76 | __END__; | ||||||||||||||||||||||||||||