nayakgi / perl-compiler

Automatically exported from code.google.com/p/perl-compiler
Other
0 stars 0 forks source link

Attribute::Handlers cannot be used in a compiled script #169

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
unsupported Attribute::Handlers in a compiled script
1. try to compile the following script
> cat script.pl
package MyTest;

use Attribute::Handlers;

sub Check :ATTR {
    print "called\n";
    print "ok\n" if ref $_[4] eq 'ARRAY' && join(',', @{$_[4]}) eq join(',', qw/a b c/);
}

sub a_sub :Check(qw/a b c/) {
    return 42;
}

print a_sub()."\n";

What is the expected output?
> perl script.pl
called
ok
42

 What do you see instead?
> ./a
42

What perl version are you using? Threaded? -DDEBUGGING? On what operating
system?
perl 5.14.3 unthreaded / centos 6.4 32 bits

Please provide any additional information below.
from CORE test op/attrhand.t
http://perldoc.perl.org/Attribute/Handlers.html

Original issue reported on code.google.com by nicolas....@gmail.com on 7 Nov 2013 at 4:06

GoogleCodeExporter commented 9 years ago
$>perlcc -O3 -r -e 'package MyTest; use Attribute::Handlers; sub Check :ATTR 
{print "called\n"; print "ok\n" if ref $_[4] eq "ARRAY" && join(",", @{$_[4]}) 
eq join(",", qw/a b c/);} sub a_sub :Check(qw/a b c/) { return 42 } print 
a_sub() . "\n";'
42

$>perl -e 'package MyTest; use Attribute::Handlers; sub Check :ATTR {print 
"called\n"; print "ok\n" if ref $_[4] eq "ARRAY" && join(",", @{$_[4]}) eq 
join(",", qw/a b c/);} sub a_sub :Check(qw/a b c/) { return 42 } print a_sub() 
. "\n";'  
called
ok
42

Original comment by todd.e.rinaldo on 23 Jan 2014 at 11:49

GoogleCodeExporter commented 9 years ago
The part that's got me confused is why it doesn't print "called"

Original comment by todd.e.rinaldo on 23 Jan 2014 at 11:50

GoogleCodeExporter commented 9 years ago
Issue 278 has been merged into this issue.

Original comment by reini.urban on 27 Jan 2014 at 8:47

GoogleCodeExporter commented 9 years ago
Of the issues relevant to us, this one is high.

Original comment by todd.e.rinaldo on 1 Feb 2014 at 12:25

GoogleCodeExporter commented 9 years ago
Disagree.

I haven't seen Attribute::Handlers in our code, and I'm vehemently against 
using it in the future. 
It's junk and dangerous code, which evals innocence attribute strings.

e.g. 
    perl -MAttribute::Handlers -e'
      sub UNIVERSAL::Help :ATTR(CODE) { $help_attr{ *{$_[1]}{NAME} } = $_[4]; } 
      sub unlink :Help(unlink xx) {}'

as used in Add::Rad::Help and xx is gone.

Original comment by reini.urban on 1 Feb 2014 at 6:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
As far as I know, Catalyst uses it heavily, right?

Common controller code:

sub access_remove : Does(ACL) : ACLDetachTo("/unauthorized") : 
AllowedRole(root)  : Local {
    my ( $self, $c ) = @_;
    my $params = $c->req->params;

    $c->model->remove_priv( $params->{'username'}, $params->{'priv'} );
    $c->model->log_access( $c->user->username, $c->stash->{'current_path'}, 1,
        qq{Removed privelige "$params->{'priv'}" from "$params->{'username'}"}
    );

    $c->redirect('access_edit');    # Re-display access_edit
}

Original comment by todd.e.rinaldo on 1 Feb 2014 at 3:49

GoogleCodeExporter commented 9 years ago
Exactly. 

:Does(ACL) will call ACL() at compile-time
:AllowedRole(root) will call root() at compile-time

I'll add a second issue for Attribute::Handlers, 
that they are crashing at an too early exit in the run-loop.

1st issue: why does it leave the runloop at all.
2nd: it should not crash at any exit() called in an inner scope.

./pccAttribute_Handlers(Perl_cv_undef+0x2ed)[0x4f435d]
./pccAttribute_Handlers(Perl_sv_clear+0x6bc)[0x544f4c]
./pccAttribute_Handlers(Perl_sv_free2+0xdd)[0x54539d]
./pccAttribute_Handlers(Perl_leave_scope+0x63b)[0x567dab]
./pccAttribute_Handlers[0x4c6176]
./pccAttribute_Handlers(Perl_my_exit+0x23)[0x4caae3]
./pccAttribute_Handlers(perl_run+0x25c)[0x4cde5c]

Original comment by reini.urban on 19 Feb 2014 at 3:31

GoogleCodeExporter commented 9 years ago

Original comment by reini.urban on 11 Jun 2014 at 11:21

GoogleCodeExporter commented 9 years ago

Original comment by reini.urban on 11 Jun 2014 at 11:23

GoogleCodeExporter commented 9 years ago
Issue 278 has been merged into this issue.

Original comment by reini.urban on 29 Aug 2014 at 1:30