| 1 | package Valiant::HTML::Tag; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # Not going to worry about @generate_indexed_names or @auto_index for now and | ||||||||||||||||||||||||||||
| 6 | # just assume they are always false | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 0 | ▶ | has 'model_name' => (is=>'ro', coerce=>sub { $_[0]=~s/\[\]$// || $_[0]=~s/\[\]\]$/]/; $_[0] }, required=>1); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 9 | 1 | has 'method_name' => (is=>'ro', required=>1); | |||||||||||||||||||||||||||
| 10 | 1 | has 'tag_helpers' => (is=>'ro', required=>1); | |||||||||||||||||||||||||||
| 11 | 0 | ▶ | has 'options' => (is=>'ro', required=>1, default=>sub { +{} }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | has 'model' => ( | |||||||||||||||||||||||||||
| 14 | is=>'ro', | ||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||
| 16 | lazy => 1, | ||||||||||||||||||||||||||||
| 17 | builder => '_build_model', | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub _build_model { | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_model: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 22 | 0 | $self->_retrieve_object(delete $self->options->{model}); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | has 'skip_default_ids' => ( | |||||||||||||||||||||||||||
| 26 | is=>'ro', | ||||||||||||||||||||||||||||
| 27 | required => 1, | ||||||||||||||||||||||||||||
| 28 | lazy => 1, | ||||||||||||||||||||||||||||
| 29 | builder => '_skip_default_ids', | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub _skip_default_ids { return delete($_[0]->options->{skip_default_ids}) ? 1:0 } | ||||||||||||||||||||||||||
|
Subroutine
_skip_default_ids: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | has 'allow_method_names_outside_model' => ( | |||||||||||||||||||||||||||
| 35 | is=>'ro', | ||||||||||||||||||||||||||||
| 36 | required => 1, | ||||||||||||||||||||||||||||
| 37 | lazy => 1, | ||||||||||||||||||||||||||||
| 38 | builder => '_allow_method_names_outside_model', | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub _allow_method_names_outside_model { return delete($_[0]->options->{allow_method_names_outside_model}) ? 1:0 } | ||||||||||||||||||||||||||
|
Subroutine
_allow_method_names_outside_model: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub _retrieve_object { | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my ($self, $object) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_retrieve_object: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ($object) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 46 | 0 | return $object; | |||||||||||||||||||||||||||
| 47 | } elsif ($self->tag_helpers->attribute_for_view_exists($self->model_name)) { | ||||||||||||||||||||||||||||
| 48 | 0 | $object = $self->tag_helpers->read_attribute_for_view($self->model_name); | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $object if defined($object); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | return bless +{}, 'Valiant::HTML::Tag::DefaultModel'; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub render { die "Not implemented!" } | ||||||||||||||||||||||||||
|
Subroutine
render: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub value { | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
value: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 0 | my $method_name = $self->method_name; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | if($self->allow_method_names_outside_object){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self->model->$method_name if $self->has_model && $self->model->can($method_name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->has_model and $self->model->can($method_name)
MC/DC0%0/2
$self->has_model and $self->model->can($method_name)
$self->has_model
$self->model->can($method_name)
Truth table0%0/3
A and B
A= $self->has_modelB= $self->model->can($method_name)
| |||||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $self->model->$method_name if $self->has_model; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | return ''; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | 1; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 NAME | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Valiant::HTML::Tag - Base class for tag objects | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | TBD | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | TBD | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | This package exposes the folllowing class methods | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | This class has the following initialization attributes | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head2 skip_default_ids | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Defaults to false. Generally we create an html C<id> attribute for the field based | ||||||||||||||||||||||||||||
| 92 | on a convention which includes the model name, index and method name. Setting this | ||||||||||||||||||||||||||||
| 93 | to true prevents that so you should set C<id> manually unless you don't want them. | ||||||||||||||||||||||||||||
| 94 | Please note that even if this is false, you can always override the C<id> on a per | ||||||||||||||||||||||||||||
| 95 | field basis by setting it manually. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head2 allow_method_names_outside_model | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Default is false. Generally we expect C<method_name> to be an actual method on the | ||||||||||||||||||||||||||||
| 100 | C<model> and if its not we expect an exception. This helps to prevent typos from | ||||||||||||||||||||||||||||
| 101 | leading to unexpected results. However sometimes you may wish create a form field that | ||||||||||||||||||||||||||||
| 102 | has a name that isn't on the model but still respects the current namespace and index. | ||||||||||||||||||||||||||||
| 103 | These names would appear in the POST request body and could be used for things other than | ||||||||||||||||||||||||||||
| 104 | updating or creating a model. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 INSTANCE METHODS | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | This package exposes the folllowing instance methods | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | L<Valiant>, L<Valiant::HTML::FormBuilder> | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | See L<Valiant> | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | See L<Valiant> | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||