Text::Xslate::Bridge::TypeDeclaration - A Mouse-based Type Validator in Xslate.
my $xslate = Text::Xslate->new( module => [ 'Text::Xslate::Bridge::TypeDeclaration' ], ); # @@ template.tx # <:- declare(name => 'Str', engine => 'Text::Xslate') -:> # <: $name :> version is <: $engine.VERSION :>. # Success! $xslate->render('template.tx', { name => 'Text::Xslate', engine => $xslate }); # Text::Xslate version is 3.4.0. # A string 'TT' is not isa 'Text::Xslate' $xslate->render('template.tx', { name => 'Text::Xslate', engine => $xslate }); # <pre class="type-declaration-mismatch"> # Declaration mismatch for `engine` # declaration: 'Text::Xslate' # value: 'TT' # </pre> # Template::Toolkit version is .
Text::Xslate::Bridge::TypeDeclaration is a type validator module in Text::Xslate templates.
The type validation of this module is base on Mouse::Util::TypeConstraints.
declare interface was implemented with reference to Smart::Args.
declare
declare(name => 'Str')
declare(user_ids => 'ArrayRef[Int]')
find_or_create_isa_type_constraint
declare(engine => 'Text::Xslate')
declare(visitor => 'Maybe[My::Model::UserAccount]')
declare(account_summary => { name => 'Str', subscriber_count => 'Int', icon => 'My::Image' })
declare(sidebar => { profile => { name => 'Str', followers => 'Int' }, recent_entries => 'ArrayRef[My::Entry]' })
declare(pair => [ 'My::UserAccount', 'My::UserAccount' ])
declare(args => [ 'Defined', 'Str', 'Maybe[Int]' ])
Text::Xslate->new( module => [ 'Text::Xslate::Bridge::TypeDeclaration' => [ # defaults method => 'declare', # method name to export validate => 1, # enable validation when truthy print => 'html', # error output format ('html', 'text' or 'none') on_mismatch => 'die', # error handler ('die', 'warn' or 'none') ] ] );
Perhaps you want to disable validation in production to prevent spoiling performance.
Text::Xslate->new( module => [ 'Text::Xslate::Bridge::TypeDeclaration' => [ validate => $ENV{PLACK_ENV} ne 'production', ], ], );
type-declaration-mismatch
Highlight by css
.type-declaration-mismatch { color: crimson; }
Lint with Test::WWW::Mechanize
# in subclass of Test::WWW::Mechanize sub _lint_content_ok { my ($self, $desc) = @_; if (my $mismatch = $self->scrape_text_by_attr('class', 'type-declaration-mismatch')) { $Test::Builder::Test->ok(0, $mismatch); }; return $self->SUPER::_lint_content_ok($desc); }
Copyright (C) pokutuna.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
pokutuna <popopopopokutuna@gmail.com>
To install Text::Xslate::Bridge::TypeDeclaration, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Xslate::Bridge::TypeDeclaration
CPAN shell
perl -MCPAN -e shell install Text::Xslate::Bridge::TypeDeclaration
For more information on module installation, please visit the detailed CPAN module installation guide.