| 1 | package HTML::FormHandler::Moose; | ||||||||||||||
| 2 | # ABSTRACT: to add FormHandler sugar | ||||||||||||||
| 3 | 148 | $HTML::FormHandler::Moose::VERSION = '0.410001'; | |||||||||||||
| 4 | 148 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 148 | ▶ | use Moose::Exporter; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 148 | ▶ | use Moose::Util::MetaRole; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 148 | ▶ | use HTML::FormHandler::Meta::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | |||||||||||||||
| 10 | 148 | Moose::Exporter->setup_import_methods( | |||||||||||||
| 11 | with_meta => [ 'has_field', 'has_page', 'has_block', 'apply' ], | ||||||||||||||
| 12 | also => 'Moose', | ||||||||||||||
| 13 | ); | ||||||||||||||
| 14 | |||||||||||||||
| 15 | sub init_meta { | ||||||||||||||
| 16 | 451 | ▶ | my $class = shift; | ||||||||||||
|
Subroutine
init_meta: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 451 | my %options = @_; | |||||||||||||
| 19 | 451 | Moose->init_meta(%options); | |||||||||||||
| 20 | my $meta = Moose::Util::MetaRole::apply_metaroles( | ||||||||||||||
| 21 | for => $options{for_class}, | ||||||||||||||
| 22 | 451 | class_metaroles => { | |||||||||||||
| 23 | class => [ 'HTML::FormHandler::Meta::Role' ] | ||||||||||||||
| 24 | } | ||||||||||||||
| 25 | ); | ||||||||||||||
| 26 | 451 | return $meta; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | sub has_field { | ||||||||||||||
| 30 | 844 | ▶ | my ( $meta, $name, %options ) = @_; | ||||||||||||
|
Subroutine
has_field: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 31 | 844 | ▶ | my $names = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | |||||||||||||||
| 33 | 844 | ▶ | unless ($meta->found_hfh) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | 228 | my @linearized_isa = $meta->linearized_isa; | |||||||||||||
| 35 | 228 | ▶ | if( grep { $_ eq 'HTML::FormHandler' || $_ eq 'HTML::FormHandler::Field' } @linearized_isa ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 36 | 227 | $meta->found_hfh(1); | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | else { | ||||||||||||||
| 39 | 1 | die "Package '" . $linearized_isa[0] . "' uses HTML::FormHandler::Moose without extending HTML::FormHandler[::Field]"; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 843 | $meta->add_to_field_list( { name => $_, %options } ) for @$names; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | sub has_page { | ||||||||||||||
| 47 | 3 | ▶ | my ( $meta, $name, %options ) = @_; | ||||||||||||
|
Subroutine
has_page: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||
| 48 | 3 | ▶ | my $names = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 3 | $meta->add_to_page_list( { name => $_, %options } ) for @$names; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | sub has_block { | ||||||||||||||
| 54 | 13 | ▶ | my ( $meta, $name, %options ) = @_; | ||||||||||||
|
Subroutine
has_block: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 55 | 13 | $meta->add_to_block_list( { name => $name, %options } ); | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | sub apply { | ||||||||||||||
| 59 | 23 | ▶ | my ( $meta, $arrayref ) = @_; | ||||||||||||
|
Subroutine
apply: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 60 | |||||||||||||||
| 61 | 23 | $meta->add_to_apply_list( @{$arrayref} ); | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 148 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 65 | 148 | 1; | |||||||||||||
| 66 | |||||||||||||||
| 67 | __END__ | ||||||||||||||
| 68 | |||||||||||||||
| 69 | =pod | ||||||||||||||
| 70 | |||||||||||||||
| 71 | =encoding UTF-8 | ||||||||||||||
| 72 | |||||||||||||||
| 73 | =head1 NAME | ||||||||||||||
| 74 | |||||||||||||||
| 75 | HTML::FormHandler::Moose - to add FormHandler sugar | ||||||||||||||
| 76 | |||||||||||||||
| 77 | =head1 VERSION | ||||||||||||||
| 78 | |||||||||||||||
| 79 | version 0.410001 | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =head1 SYNOPSIS | ||||||||||||||
| 82 | |||||||||||||||
| 83 | Enables the use of field specification sugar (has_field). | ||||||||||||||
| 84 | Use this module instead of C< use Moose; > | ||||||||||||||
| 85 | |||||||||||||||
| 86 | package MyApp::Form::Foo; | ||||||||||||||
| 87 | use HTML::FormHandler::Moose; | ||||||||||||||
| 88 | extends 'HTML::FormHandler'; | ||||||||||||||
| 89 | |||||||||||||||
| 90 | has_field 'username' => ( type => 'Text', ... ); | ||||||||||||||
| 91 | has_field 'something_else' => ( ... ); | ||||||||||||||
| 92 | |||||||||||||||
| 93 | no HTML::FormHandler::Moose; | ||||||||||||||
| 94 | 1; | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =head1 AUTHOR | ||||||||||||||
| 97 | |||||||||||||||
| 98 | FormHandler Contributors - see HTML::FormHandler | ||||||||||||||
| 99 | |||||||||||||||
| 100 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 101 | |||||||||||||||
| 102 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||||||
| 103 | |||||||||||||||
| 104 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 105 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 106 | |||||||||||||||
| 107 | =cut | ||||||||||||||