| 1 | package FormValidator::Nested::ProfileProvider::YAML; | ||||||||||
| 2 | 18 | ▶ | use Any::Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 18 | ▶ | use Any::Moose 'X::Types::Path::Class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 18 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 18 | with 'FormValidator::Nested::ProfileProvider'; | |||||||||
| 6 | |||||||||||
| 7 | 18 | our $EXT = '.yml'; | |||||||||
| 8 | |||||||||||
| 9 | 18 | ▶ | use FormValidator::Nested::ProfileProvider; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 18 | ▶ | use YAML::Syck; $YAML::Syck::ImplicitUnicode = 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 18 | ▶ | use Path::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 18 | has 'dir' => ( | |||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | isa => 'Path::Class::Dir', | ||||||||||
| 17 | coerce => 1, | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 18 | __PACKAGE__->meta->make_immutable; | |||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | sub _build_profile_keys { | ||||||||
|
Subroutine
_build_profile_keys: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 2 | my $self = shift; | |||||||||
| 26 | |||||||||||
| 27 | 2 | my @profile_keys; | |||||||||
| 28 | $self->dir->recurse( | ||||||||||
| 29 | 26 | ▶ | callback => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 30 | 26 | my $path = shift; | |||||||||
| 31 | 26 | ▶ | if ( $path !~ m/$EXT$/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 4 | return; | |||||||||
| 33 | } | ||||||||||
| 34 | 22 | my $relative_path = $path->relative($self->dir); | |||||||||
| 35 | 22 | $relative_path =~ s/$EXT$//; | |||||||||
| 36 | 22 | push @profile_keys, $relative_path; | |||||||||
| 37 | } | ||||||||||
| 38 | 2 | ); | |||||||||
| 39 | 2 | return \@profile_keys; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | 44 | ▶ | sub get_profile_data { | ||||||||
|
Subroutine
get_profile_data: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 44 | 44 | my $self = shift; | |||||||||
| 45 | 44 | my $key = shift; | |||||||||
| 46 | |||||||||||
| 47 | 44 | my @path = split m{/}, $key; | |||||||||
| 48 | 44 | $path[-1] .= $EXT; | |||||||||
| 49 | |||||||||||
| 50 | 44 | my $file = Path::Class::File->new($self->dir, @path); | |||||||||
| 51 | 44 | ▶ | if ( !-f $file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 2 | return 0; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 42 | my $profile = YAML::Syck::LoadFile(Path::Class::File->new($self->dir, @path)); | |||||||||
| 56 | |||||||||||
| 57 | 42 | return $profile; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 18 | 1; | |||||||||
| 61 | |||||||||||