Plift
view release on metacpan or search on metacpan
lib/Plift/Context.pm view on Meta::CPAN
package Plift::Context;
use Moo;
use Carp;
use XML::LibXML::jQuery;
use JSON 'to_json';
use Encode 'encode';
use namespace::clean;
use Ref::Util qw/ is_hashref is_blessed_ref /;
has 'helper', is => 'ro';
has 'wrapper', is => 'ro';
has 'template', is => 'ro', required => 1;
has 'encoding', is => 'ro', default => 'UTF-8';
has 'loop_var', is => 'ro', default => 'loop';
has 'metadata_key', is => 'ro', default => 'meta';
has 'handlers', is => 'ro', default => sub { [] };
has 'active_handlers', is => 'rw';
has 'inactive_handlers', is => 'rw';
has 'internal_id_attribute', is => 'ro', default => 'data-plift-id';
has '_load_template', is => 'ro', required => 1, init_arg => 'load_template';
has '_load_snippet', is => 'ro', required => 1, init_arg => 'load_snippet';
has '_run_hooks', is => 'ro', required => 1, init_arg => 'run_hooks';
has 'document', is => 'rw', init_arg => undef;
has 'is_rendering', is => 'rw', init_arg => undef, default => 0;
has 'is_aborted', is => 'rw', init_arg => undef, default => '';
has '_data_stack', is => 'ro', init_arg => 'data_stack', default => sub { [] };
has '_directive_stack', is => 'ro', init_arg => undef, default => sub { [] };
sub AUTOLOAD {
my $self = shift;
my ($package, $method) = our $AUTOLOAD =~ /^(.+)::(.+)$/;
Carp::croak "Undefined subroutine &${package}::$method called"
unless is_blessed_ref $self && $self->isa(__PACKAGE__);
return if $method eq 'DESTROY';
Carp::croak qq{Can't locate object method "$method" via package "$package"}
unless $self->helper && $self->helper->can($method);
$self->helper->$method(@_);
}
sub BUILD {
my $self = shift;
# coerse array indo hash
foreach my $attr (qw/ active_handlers inactive_handlers/) {
$self->$attr({ map { $_ => 1 } @{ $self->$attr } })
if $self->$attr;
}
}
sub metadata {
my $self = shift;
my $key = $self->metadata_key;
my $data = $self->data;
$data->{$key} = {} unless exists $data->{$key};
$data->{$key};
}
( run in 1.770 second using v1.01-cache-2.11-cpan-39bf76dae61 )