Seems, you're doing some kind of lazy cache clearing? Perhaps the situation can be relieved a bit

Maybe just:

with_cache_cleared_do { some_sub_requesting_the_data; };

Example:

use strict; use warnings; { #--- confine flag in lexical scope my $refresh_request_flag; #--- use closures to access flag sub refresh_requested { return !! $refresh_request_flag } sub with_cache_cleared_do (&) { $refresh_request_flag = 1; my @result = shift->(); # run block $refresh_request_flag = 0; return unless defined wantarray; return wantarray ? @result : $result[0]; } } # usage: -run: with_cache_cleared_do { some block }; # -check: refresh_requested() #--- that's it - now the tests ... use Test::Simple tests => 6; ok( ! refresh_requested() , 'before: flag is cleared' ); with_cache_cleared_do { ok( refresh_requested() , 'flag set within bl +ock' ); }; ok( ! refresh_requested() , 'after: flag is cleared agai +n' ); sub nested { ok( ( $_[0] == 42 and refresh_requested() ), 'flag set within nested calls with parameters') } with_cache_cleared_do { nested( 42 ) }; my $x = with_cache_cleared_do { return 'foo'; }; ok ( $x eq 'foo' , 'result in scalar context' ); my @x = with_cache_cleared_do { return ( 'one', refresh_requested() ) +; }; ok( ( $x[0] eq 'one' and $x[1] == 1 ) , 'result in list context' );

HTH

In reply to Re: Detect a localized variable by Perlbotics
in thread Detect a localized variable by Sewi

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.