Catalyst-Controller-BindLex
view release on metacpan or search on metacpan
name: Catalyst-Controller-BindLex
no_index:
directory:
- inc
- t
requires:
Array::RefElem: 0
Catalyst::Runtime: 0
Devel::Caller: 0
Devel::LexAlias: 0
PadWalker: 0
Test::use::ok: 0
perl: 5.8.1
version: 0.05
Makefile.PL view on Meta::CPAN
use inc::Module::Install 0.65;
name 'Catalyst-Controller-BindLex';
all_from 'lib/Catalyst/Controller/BindLex.pm';
perl_version '5.8.1';
requires 'Catalyst::Runtime';
requires 'PadWalker';
requires 'Devel::LexAlias';
requires 'Devel::Caller';
requires 'Array::RefElem';
requires 'Test::use::ok';
auto_install;
WriteAll;
sub counter : Local {
my ( $self, $c ) = @_;
my $count : Session;
$c->res->body( "request number " . ++$count );
}
DESCRIPTION
This plugin lets you put your lexicals on the stash and elsewhere very
easily.
It uses some funky modules to get its job done: PadWalker,
Array::RefElem, Devel::Caller, Devel::LexAlias, and attributes. In some
people's opinion this hurts this plugin's reputation ;-).
If you use the same name for two variables with the same storage binding
attribute they will be aliased to each other, so you can use this for
reading as well as writing values across controller subs. This is almost
like sharing your lexical scope.
WHY ISN'T THIS A PLUGIN?
The way attributes are handled this can't be a plugin - the
add
__PACKAGE__->config->{bindlex}{Param} => sub { $_[0]->req->params };
AUTHORS
Matt S. Trout
Yuval Kogman
SEE ALSO
PadWalker, Array::RefElem, Devel::Caller, Devel::LexAlias,
Sub::Parameters
COPYRIGHT & LICENSE
Copyright (c) 2005 the aforementioned authors. All rights
reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
lib/Catalyst/Controller/BindLex.pm view on Meta::CPAN
use base qw/Catalyst::Controller/;
# these won't help... ;-)
use strict;
use warnings;
no warnings 'uninitialized'; # i hate those
# dear god
use attributes ();
use NEXT ();
use PadWalker ();
use Array::RefElem ();
use Devel::Caller ();
use Devel::LexAlias ();
use Scalar::Util ();
use Carp ();
our $VERSION = '0.05';
sub bindlex_default_config {
map { ucfirst() . 'ed' => $_, ucfirst() => $_} qw/stash session flash/;
lib/Catalyst/Controller/BindLex.pm view on Meta::CPAN
sub _find_in_pad {
# find the name that corresponds to a reference
my ( $level, $var_ref ) = @_;
# first we need to sub to look in
# for some reason peek_my($level) doesn't work here
# perhaps it's with respect to the point at which the attribute handler
# was invoked, when the variables don't exist yet.
my $sub = Devel::Caller::caller_cv($level);
my $pad = PadWalker::peek_sub($sub);
my %ref_to_name = reverse %$pad;
return $ref_to_name{$var_ref} || die "panic: Can't find $var_ref in the the caller's lexical pad";
}
BEGIN {
# generate generic handler wrappers for all ref types that try to play safe with other plugins
for ( qw/ARRAY SCALAR HASH/ ) {
eval 'sub MODIFY_' . $_ . '_ATTRIBUTES {
my ( $pkg, $ref, @attrs ) = @_;
lib/Catalyst/Controller/BindLex.pm view on Meta::CPAN
understand it well enough to fix anything that goes wrong, then set
__PACKAGE__->config->{unsafe_bindlex_ok} = 1;
in your controller class to suppress the startup warning.
=head1 DESCRIPTION
This plugin lets you put your lexicals on the stash and elsewhere very easily.
It uses some funky modules to get its job done: L<PadWalker>,
L<Array::RefElem>, L<Devel::Caller>, L<Devel::LexAlias>, and L<attributes>. In
some people's opinion this hurts this plugin's reputation ;-).
If you use the same name for two variables with the same storage binding
attribute they will be aliased to each other, so you can use this for reading
as well as writing values across controller subs. This is almost like sharing
your lexical scope.
=head1 WHY ISN'T THIS A PLUGIN?
lib/Catalyst/Controller/BindLex.pm view on Meta::CPAN
=back
=head1 AUTHORS
Matt S. Trout
Yuval Kogman
=head1 SEE ALSO
L<PadWalker>, L<Array::RefElem>, L<Devel::Caller>, L<Devel::LexAlias>, L<Sub::Parameters>
=head1 COPYRIGHT & LICENSE
Copyright (c) 2005 the aforementioned authors. All rights
reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
=cut
( run in 0.752 second using v1.01-cache-2.11-cpan-05444aca049 )