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 ]

scrottie (4167)

scrottie
  scott@slowass.net
http://slowass.net/

My email address is scott@slowass.net. Spam me harder! *moan*

Journal of scrottie (4167)

Thursday March 09, 2006
04:02 PM

autobox example to subscript hashrefs like $x-<y-<z

[ #28941 ]

perl -e 'use connect; use autobox; use autoboxglue; print config->path->templates, "\n"; '

Explanation: I've been writing config->{path}->{templates}, but I've been working around a Python programmer, and I've been trying to make my code as spiffy as possible, among other things to show off. I decided that this construct was ugly, and it would be much nicer if I could just write config->path->templates instead. After all, since config is a sub, why couldn't path and templates be methods? With autobox, you can call methods in non-blessed references, so this was easy as cake.

Somewhere in the bowels of connect.pm:

        *{$caller.'::config'} = sub {
                return {
                        path => {
                                # ...
                                templates => '/home/improv/templates',
                        },
                };
        };

autoboxglue.pm:

    package HASH;

    sub AUTOLOAD :lvalue {
            my $method = $AUTOLOAD; $method =~ s/.*:://;
            return if $method eq 'DESTROY';
            my $hashref = shift;
            $hashref->{$method};
    }

1;