| 1 | package SyForm::CommonRole::GlobalHTML; | ||||||||||
| 2 | 7 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 7 | $SyForm::CommonRole::GlobalHTML::AUTHORITY = 'cpan:GETTY'; | |||||||||
| 4 | } | ||||||||||
| 5 | # ABSTRACT: Standard role for objects with HTML global attributes | ||||||||||
| 6 | 7 | $SyForm::CommonRole::GlobalHTML::VERSION = '0.103'; | |||||||||
| 7 | 7 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 7 | our @attributes = qw( | |||||||||
| 10 | class | ||||||||||
| 11 | accesskey | ||||||||||
| 12 | contenteditable | ||||||||||
| 13 | contextmenu | ||||||||||
| 14 | dir | ||||||||||
| 15 | draggable | ||||||||||
| 16 | dropzone | ||||||||||
| 17 | hidden | ||||||||||
| 18 | lang | ||||||||||
| 19 | spellcheck | ||||||||||
| 20 | style | ||||||||||
| 21 | tabindex | ||||||||||
| 22 | title | ||||||||||
| 23 | translate | ||||||||||
| 24 | id | ||||||||||
| 25 | name | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 7 | for my $attribute (@attributes) { | |||||||||
| 29 | 112 | has $attribute => ( | |||||||||
| 30 | is => 'ro', | ||||||||||
| 31 | predicate => 1, | ||||||||||
| 32 | ); | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 7 | has data => ( | |||||||||
| 36 | is => 'ro', | ||||||||||
| 37 | predicate => 1, | ||||||||||
| 38 | ); | ||||||||||
| 39 | |||||||||||
| 40 | 7 | has data_attributes => ( | |||||||||
| 41 | is => 'lazy', | ||||||||||
| 42 | init_arg => undef, | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | 39 | ▶ | sub _build_data_attributes { | ||||||||
|
Subroutine
_build_data_attributes: called CC=3 SCAR=11.0
| |||||||||||
| 46 | 39 | my ( $self ) = @_; | |||||||||
| 47 | 39 | ▶ | return {} unless $self->has_data; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 2 | my %data_attributes; | |||||||||
| 49 | 2 | for my $key (sort { $a cmp $b } keys %{$self->data}) { | |||||||||
| 50 | 4 | my $value = $self->data->{$key}; | |||||||||
| 51 | 4 | $key =~ s/_/-/g; | |||||||||
| 52 | 4 | $data_attributes{'data-'.$key} = $value; | |||||||||
| 53 | } | ||||||||||
| 54 | 2 | return { %data_attributes }; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 7 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||