Debian Codegraph @

lib/HTML/FormHandler/Widget/Form/Role/HTMLAttributes.pm

raw
1 package HTML::FormHandler::Widget::Form::Role::HTMLAttributes;
2 # ABSTRACT: set HTML attributes on the form tag
3 $HTML::FormHandler::Widget::Form::Role::HTMLAttributes::VERSION = '0.410002';
4 use Moose::Role;
5
6 sub html_form_tag {
7 my $self = shift;
8
9 my @attr_accessors = (
10 [ action => 'action' ],
11 [ id => 'name' ],
12 [ method => 'http_method' ],
13 [ enctype => 'enctype' ],
14 [ style => 'style' ],
15 );
16
17 # make the element_attr a safe default
18 my $element_attr = {};
19 # Assuming that self is a form
20 $element_attr = { %{$self->form_element_attr} } if ( $self->can( 'form_element_attr' ) );
21 # Assuming that self is a field
22 $element_attr = { %{$self->element_attr} } if ( $self->can( 'element_attr' ) );
23
24 foreach my $attr_pair (@attr_accessors) {
25 my $attr = $attr_pair->[0];
26 my $accessor = $attr_pair->[1];
27 if ( !exists $element_attr->{$attr} && defined( my $value = $self->$accessor ) ) {
28 $element_attr->{$attr} = $self->$accessor;
29 }
30 }
31
32 my $output = '<form';
33 foreach my $attr ( sort keys %$element_attr ) {
34 $output .= qq{ $attr="} . $element_attr->{$attr} . qq{"};
35 }
36
37 $output .= " >\n";
38 return $output;
39 }
40
41 no Moose::Role;
42 1;
43
44 __END__
45
46 =pod
47
48 =encoding UTF-8
49
50 =head1 NAME
51
52 HTML::FormHandler::Widget::Form::Role::HTMLAttributes - set HTML attributes on the form tag
53
54 =head1 VERSION
55
56 version 0.410002
57
58 =head1 AUTHOR
59
60 FormHandler Contributors - see HTML::FormHandler
61
62 =head1 COPYRIGHT AND LICENSE
63
64 This software is copyright (c) 2017 by Gerda Shank.
65
66 This is free software; you can redistribute it and/or modify it under
67 the same terms as the Perl 5 programming language system itself.
68
69 =cut