Last active
February 22, 2020 00:05
-
-
Save jjn1056/7995a1e6e974c1b2a2013227579dece6 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
package View::User; | |
use Template::Perl; | |
use Moo; | |
has 'model' => (is=>'ro', required=>1); | |
sub template { | |
my ($class, $builder) = @_; | |
# Builder can access $self, but can localize a context like Handlebars | |
# and possible useful to have its own stash as well for managing layot | |
# logic. | |
# all defined views are also components | |
return $builder | |
->form(method=>'POST', class=>'form-signin', model=>sub {$_->model}) | |
->input(class=>'aaa') | |
->input(class=>'bbb') | |
->if(sub { $_->model->invalid }) | |
->div | |
->text(sub { $_->model->error_for('password_confirmation')->first }) | |
->end | |
->end | |
->foreach(sub {$_->model->friends}) | |
->li | |
->text(sub { | |
my ($self, $i, $friend) = @_; | |
$friend->name; | |
$builder->ol(for=>sub {$friend->email_addresses}) | |
->li | |
->text(sub {my ($self, $email) = @_; $email->string}) | |
}) | |
->end | |
->end; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment