Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Seems to me that this is easy to solve.

Just implement a plugin that clashes with $c->stash, and override it with a method that filters things in the stash using a regular expression. This way you'll get more control over what the stash dumps into your view modules, with something easy as $c->stash( qr/.../ ). Of course, with no arguments, $c->stash() will dump everything out, as expected.

Please note that by using this, you can avoid rubishness trought being not lazy, and get all control your need over your view modules income data, without hurting the freedom of others. I would think twice before using such a thing. ;-)

All code is untested, and extremely experimental.

package Catalyst::Plugin::Stash::Filter; use warnings; use strict; use NEXT; 1; package Catalyst::Engine; use warnings; use strict; use NEXT; =item $c->stash If the first argument is a hashref, returns a hashref containing only data keys that matches $_[0]->{FILTER}. Otherwise, returns a hashref containing all your data. $c->stash->{foo} ||= 'yada'; print $c->stash->{foo}; =cut sub stash { my $self = shift; # this makes the real stash() method magic... my $stash = $self->NEXT::stash(); # this filters out everything unwanted or unknow... if( UNIVERSAL::isa( $_[0], 'HASH') && exists $_[0]->{FILTER} ){ # $strip is just a boolean. my( $criteria, $strip ) = ( $_[0]->{FILTER}, $_[0]->{STRIP} ); ## err... "borrowed" from Andy Wardley's AppConfig::State module. ## Original comments follow. ## thanks, Andy. # extract relevant keys and slice out corresponding values my @keys = grep(/$criteria/, keys %{ $stash }); my @vals = @{ $stash }{ @keys }; my %set; # clean off the $criteria part if $strip is set @keys = map { s/$criteria//; $_ } @keys if $strip; # slice values into the target hash @set{ @keys } = @vals; $stash = \%set; } return $stash; } 1;

In reply to Re: Catalyst and the stash by monsieur_champs
in thread Catalyst and the stash by Mutant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2014-09-16 02:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (155 votes), past polls