| 1 | package SyForm; | ||||||||||||||||||||
| 2 | 7 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 7 | $SyForm::AUTHORITY = 'cpan:GETTY'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | # ABSTRACT: Easy form management | ||||||||||||||||||||
| 6 | 7 | $SyForm::VERSION = '0.103'; | |||||||||||||||||||
| 7 | 7 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 7 | ▶ | use Tie::IxHash; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 7 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 7 | ▶ | use SyForm::Exception; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 7 | with($_) for (qw( | |||||||||||||||||||
| 13 | MooX::Traits | ||||||||||||||||||||
| 14 | SyForm::Role::Process | ||||||||||||||||||||
| 15 | SyForm::Role::Label | ||||||||||||||||||||
| 16 | )); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | ####################### | ||||||||||||||||||||
| 19 | # | ||||||||||||||||||||
| 20 | # Class Default Config | ||||||||||||||||||||
| 21 | # | ||||||||||||||||||||
| 22 | ####################### | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 7 | has name => ( | |||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||
| 26 | predicate => 1, | ||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 7 | has fields_list => ( | |||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||
| 31 | init_arg => 'fields', | ||||||||||||||||||||
| 32 | required => 1, | ||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 7 | has fields => ( | |||||||||||||||||||
| 36 | is => 'lazy', | ||||||||||||||||||||
| 37 | init_arg => undef, | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | 14 | ▶ | sub field { shift->fields->FETCH(@_) } | ||||||||||||||||||
|
Subroutine
field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 7 | ▶ | sub _build_fields { | ||||||||||||||||||
|
Subroutine
_build_fields: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 42 | 7 | my ( $self ) = @_; | |||||||||||||||||||
| 43 | 7 | my $fields = Tie::IxHash->new; | |||||||||||||||||||
| 44 | 7 | eval { | |||||||||||||||||||
| 45 | 7 | my $fields_list = Tie::IxHash->new(@{$self->fields_list}); | |||||||||||||||||||
| 46 | 7 | for my $name ($fields_list->Keys) { | |||||||||||||||||||
| 47 | 27 | my %field_args = %{$fields_list->FETCH($name)}; | |||||||||||||||||||
| 48 | 27 | $fields->Push($name, $self->new_field($name, %field_args)); | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | }; | ||||||||||||||||||||
| 51 | 7 | ▶ | SyForm->throw( UnknownErrorOnBuildFields => $self, $@ ) if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 7 | return $fields; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 7 | has field_names => ( | |||||||||||||||||||
| 56 | is => 'lazy', | ||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 2 | ▶ | sub _build_field_names { | ||||||||||||||||||
|
Subroutine
_build_field_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 60 | 2 | my ( $self ) = @_; | |||||||||||||||||||
| 61 | 2 | return [map { $_->name } $self->fields->Values]; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 7 | has field_class => ( | |||||||||||||||||||
| 65 | is => 'lazy', | ||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 7 | ▶ | sub _build_field_class { return 'SyForm::Field' } | ||||||||||||||||||
|
Subroutine
_build_field_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 7 | has loaded_field_class => ( | |||||||||||||||||||
| 71 | is => 'lazy', | ||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 7 | ▶ | sub _build_loaded_field_class { | ||||||||||||||||||
|
Subroutine
_build_loaded_field_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 75 | 7 | my ( $self ) = @_; | |||||||||||||||||||
| 76 | 7 | return use_module($self->field_class); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 27 | ▶ | sub new_field { | ||||||||||||||||||
|
Subroutine
new_field: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||
| 80 | 27 | my ( $self, $name, %field_args ) = @_; | |||||||||||||||||||
| 81 | 27 | my $field; | |||||||||||||||||||
| 82 | 27 | ▶ | my $class = delete $field_args{class} || $self->loaded_field_class; | ||||||||||||||||||
|
Condition33%1/3
delete $field_args{'class'} || $self->loaded_field_class
MC/DC0%0/2
delete $field_args{'class'} || $self->loaded_field_class
delete $field_args{'class'}
$self->loaded_field_class
Truth table33%1/3
A || B
A= delete $field_args{'class'}B= $self->loaded_field_class
| |||||||||||||||||||||
| 83 | 27 | return $class->new( | |||||||||||||||||||
| 84 | syform => $self, | ||||||||||||||||||||
| 85 | name => $name, | ||||||||||||||||||||
| 86 | %field_args, | ||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | ▶ | sub throw { | ||||||||||||||||||
|
Subroutine
throw: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 91 | 0 | my ( $class, $exception, @args ) = @_; | |||||||||||||||||||
| 92 | 0 | ▶ | SyForm::Exception->throw($exception) if scalar(@args) == 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 0 | use_module('SyForm::Exception::'.$exception)->throw_with_args(@args); | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 7 | 1; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||