Statocles icon indicating copy to clipboard operation
Statocles copied to clipboard

Add data helper method on objects with data attributes

Open preaction opened this issue 10 years ago • 0 comments

To make the templates easier to work with, it'd be nice if we had a data() method that would, if given an argument, deref the first level of reference.

my $data = $self->data; # get the raw hashref
my @ary = $self->data( 'ary' ); # deref the arrayref
my %hash = $self->data( 'hash' ); # deref the hashref

This will be most useful for arrays, as it turns

% for my $item ( @{ $self->data->{ ary } } ) {

into

% for my $item ( $self->data( 'ary' ) ) {

preaction avatar Dec 20 '15 04:12 preaction