Created
June 29, 2020 17:07
-
-
Save jjn1056/bd2871293156435dcbd1b24a4f31c220 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Template syntax update to allow capture blocks with "sub() {" | |
% use experimental 'signatures'; | |
%= formbuilder->form(method => 'POST', sub($fb) { | |
<fieldset> | |
<legend>My Test Form</legend> | |
%= $fb->input(type='text'); | |
%= $fb->input(type='text'); | |
</fieldset> | |
% }); | |
# Could produce HTML like | |
<form method='post'> | |
<fieldset> | |
<legend>My Test Form</legend> | |
<input .... > | |
<input .... > | |
</fieldset> | |
</form> | |
# Code sketch of function | |
package Formbuilder; | |
use Moo; | |
sub form { | |
my ($self, $content, %attrs) = (shift, _parse_proto(@_)); | |
my $inner = $content->($self); | |
my $attrs = join ' ', map { "$_='$attrs{$_}'" } keys %attrs; | |
return "<form $attrs>$inner</form>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment