Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created June 29, 2020 17:07
Show Gist options
  • Save jjn1056/bd2871293156435dcbd1b24a4f31c220 to your computer and use it in GitHub Desktop.
Save jjn1056/bd2871293156435dcbd1b24a4f31c220 to your computer and use it in GitHub Desktop.
## 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