| 1 | package SyForm::ViewField::LabelHTML; | ||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | $SyForm::ViewField::LabelHTML::AUTHORITY = 'cpan:GETTY'; | |||||||||
| 4 | } | ||||||||||
| 5 | 3 | $SyForm::ViewField::LabelHTML::VERSION = '0.103'; | |||||||||
| 6 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use List::MoreUtils qw( uniq ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use HTML::Declare ':all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | with qw( | |||||||||
| 11 | MooX::Traits | ||||||||||
| 12 | SyForm::CommonRole::GlobalHTML | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | 3 | has label => ( | |||||||||
| 16 | is => 'ro', | ||||||||||
| 17 | required => 1, | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 3 | my @own_attributes = qw( for ); | |||||||||
| 21 | |||||||||||
| 22 | 3 | for my $attribute (@own_attributes, qw( errors )) { | |||||||||
| 23 | 6 | has $attribute => ( | |||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | predicate => 1, | ||||||||||
| 26 | ); | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 3 | has html_declare => ( | |||||||||
| 30 | is => 'lazy', | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | 13 | ▶ | sub _build_html_declare { | ||||||||
|
Subroutine
_build_html_declare: called CC=6 SCAR=18.0
| |||||||||||
| 34 | 13 | my ( $self ) = @_; | |||||||||
| 35 | 13 | my %html_attributes = %{$self->data_attributes}; | |||||||||
| 36 | 13 | for my $key (@SyForm::CommonRole::GlobalHTML::attributes) { | |||||||||
| 37 | 208 | my $has = 'has_'.$key; | |||||||||
| 38 | 208 | ▶ | $html_attributes{$key} = $self->$key if $self->$has; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | } | ||||||||||
| 40 | 13 | for my $key (@own_attributes) { | |||||||||
| 41 | 13 | my $has = 'has_'.$key; | |||||||||
| 42 | 13 | ▶ | $html_attributes{$key} = $self->$key if $self->$has; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | } | ||||||||||
| 44 | $html_attributes{_} = [ | ||||||||||
| 45 | $self->label, | ||||||||||
| 46 | $self->has_errors ? ( | ||||||||||
| 47 | 13 | ▶ | map { EM { _ => $_->message } } @{$self->errors} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | ) : (), | ||||||||||
| 49 | ], | ||||||||||
| 50 | return LABEL { %html_attributes }; | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 3 | 1; | |||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||