Created
December 13, 2011 18:54
-
-
Save msztolcman/1473342 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use 5.010; | |
use Data::Dumper; | |
$Data::Dumper::Sortkeys = 1; | |
$Data::Dumper::Terse = 1; | |
$Data::Dumper::Indent = 1; | |
$Data::Dumper::Quotekeys = 1; | |
sub cgi_dump { say &Dumper; }; | |
use Attribute::Handlers; | |
my %USER; | |
sub UNIVERSAL::needs_auth : ATTR(CODE) { | |
my ($pkg, $sym, $code, ) = @_; | |
no warnings 'redefine'; | |
*{$sym} = sub { | |
my $fun = *{$sym}{NAME}; | |
if (!%USER) { | |
say "$fun: not logged in"; | |
return; | |
} | |
goto &$code; | |
} | |
} | |
sub t1 : needs_auth { | |
say 't1'; | |
} | |
sub t2 : needs_auth { | |
say 't2'; | |
} | |
say 'pre auth:'; | |
t1; | |
t2; | |
%USER = (name => 'mysz', ); | |
say 'post auth:'; | |
t1; | |
t2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment