Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rcaputo (9040)

rcaputo
  (email not shown publicly)
http://poe.perl.org/

Journal of rcaputo (9040)

Sunday September 06, 2009
01:51 AM

Help me rename Lexical::Persistence

[ #39588 ]

"Persistence" implies that data will be saved and loaded from disk, to a database, or some other persistent storage. That's not what the module does, so I think it needs a new name.

Lexical::Persistence objects are closures that make the values of lexical variables stick (or persist) in everything they call. In the following example, the Lexical::Persistence object makes sure that getter()'s version of $x contains the value stored by setter().

use Lexical::Persistence;

my $lp = Lexical::Persistence->new();
$lp->call(\&setter);
$lp->call(\&getter);

sub setter { my $x = "some value" }
sub getter { print my $x, "\n" }

Lexical::Persistence's closures are objects. Programs may examine and manipulate their contents between calls. The following code displays something like this:

My mind is going. I can feel it.
My is going. I can feel it.
My is going. I feel it.
My going. I feel it.
My going. I feel
My I feel
My I
My

Here's the example:

use Lexical::Persistence;

my $lp = Lexical::Persistence->new();
$lp->set_context(
    _ => {
        '@mind' => [qw(My mind is going. I can feel it.)]
    }
);

while (1) {
    $lp->call(\&display);
    my $mind = $lp->get_context("_")->{'@mind'};
    splice @$mind, rand(@$mind), 1;
    last unless @$mind;
}

sub display {
    my @mind;
    print "@mind\n";
}

So, what would be a better name for this module?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • You need a word that's not so heavy as "persistent", which is also already in use with a different meaning, as you say.

    So, here are some words for you:

    • sticky
    • static
    • state (I don't like this one, but that's what perl 5.10 uses)

    My favorite is "sticky", which has a very informal feel about it.

    Also, you may want to try out the Reverse Dictionary Lookup [onelook.com], throw some words at it, and see how you like the alternative words that it comes up with.

  • Lexical::Environment

    --
    rjbs