Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RT 27364: DESTROY and AUTOLOAD don't parse as subs without 'sub' #31

Closed
moregan opened this issue Jan 30, 2014 · 2 comments
Closed

RT 27364: DESTROY and AUTOLOAD don't parse as subs without 'sub' #31

moregan opened this issue Jan 30, 2014 · 2 comments

Comments

@moregan
Copy link
Collaborator

moregan commented Jan 30, 2014

Jeff Thalhammer points out that Perl allows you to omit 'sub' from DESTROY and AUTOLOAD:

moregan@moregan[~]$ perl -WE 'AUTOLOAD {1;}'
moregan@moregan[~]$ perl -WE 'package x; DESTROY {1;}'
moregan@moregan[~]$ 

but PPI doesn't recognized them as subs unless 'sub' is included:

ppidump 'AUTOLOAD {;}'
                    PPI::Document
                      PPI::Statement
[    1,   1,   1 ]     PPI::Token::Word     'AUTOLOAD'
                        PPI::Structure::Block   { ... }
                          PPI::Statement::Null
[    1,  11,  11 ]         PPI::Token::Structure    ';'

ppidump 'sub AUTOLOAD {;}'
                    PPI::Document
                      PPI::Statement::Sub
[    1,   1,   1 ]     PPI::Token::Word     'sub'
[    1,   5,   5 ]     PPI::Token::Word     'AUTOLOAD'
                        PPI::Structure::Block   { ... }
                          PPI::Statement::Null
[    1,  15,  15 ]         PPI::Token::Structure    ';'

https://rt.cpan.org/Public/Bug/Display.html?id=27364

moregan added a commit to moregan/PPI that referenced this issue Feb 12, 2014
moregan added a commit to moregan/PPI that referenced this issue Feb 28, 2014
moregan added a commit to moregan/PPI that referenced this issue Feb 28, 2014
moregan added a commit to moregan/PPI that referenced this issue Feb 28, 2014
@moregan
Copy link
Collaborator Author

moregan commented Feb 28, 2014

A pernicious aspect of this problem is that after an AUTOLOAD or DESTROY without 'sub', PPI stops creating PPI::Statement::Sub, at least sometimes:

ppidump 'DESTROY {1;} sub foo {1;}' 
                    PPI::Document
                      PPI::Statement
[    1,   1,   1 ]     PPI::Token::Word     'DESTROY'
                        PPI::Structure::Block   { ... }
                          PPI::Statement
[    1,  10,  10 ]         PPI::Token::Number   '1'
[    1,  11,  11 ]         PPI::Token::Structure    ';'
[    1,  14,  14 ]     PPI::Token::Word     'sub'
[    1,  18,  18 ]     PPI::Token::Word     'foo'
                        PPI::Structure::Block   { ... }
                          PPI::Statement
[    1,  23,  23 ]         PPI::Token::Number   '1'
[    1,  24,  24 ]         PPI::Token::Structure    ';'
                    PPI::Structure::Block   { ... }

And not just one sub gets missed:

ppidump 'DESTROY {1;} sub foo {1;} sub bar {1;}'
                    PPI::Document
                      PPI::Statement
[    1,   1,   1 ]     PPI::Token::Word     'DESTROY'
                        PPI::Structure::Block   { ... }
                          PPI::Statement
[    1,  10,  10 ]         PPI::Token::Number   '1'
[    1,  11,  11 ]         PPI::Token::Structure    ';'
[    1,  14,  14 ]     PPI::Token::Word     'sub'
[    1,  18,  18 ]     PPI::Token::Word     'foo'
                        PPI::Structure::Block   { ... }
                          PPI::Statement
[    1,  23,  23 ]         PPI::Token::Number   '1'
[    1,  24,  24 ]         PPI::Token::Structure    ';'
[    1,  27,  27 ]     PPI::Token::Word     'sub'
[    1,  31,  31 ]     PPI::Token::Word     'bar'
                        PPI::Structure::Block   { ... }
                          PPI::Statement
[    1,  36,  36 ]         PPI::Token::Number   '1'
[    1,  37,  37 ]         PPI::Token::Structure    ';'

The problem goes away (in this example) when #39 is in effect.

moregan added a commit to moregan/PPI that referenced this issue Mar 4, 2014
moregan added a commit to moregan/PPI that referenced this issue Mar 6, 2014
moregan added a commit to moregan/PPI that referenced this issue Mar 14, 2014
moregan added a commit to moregan/PPI that referenced this issue Mar 14, 2014
moregan added a commit to moregan/PPI that referenced this issue Mar 14, 2014
moregan added a commit to moregan/PPI that referenced this issue Mar 15, 2014
moregan added a commit to moregan/PPI that referenced this issue Aug 23, 2014
@wchristian
Copy link
Member

The full version of the fix for this is now released to CPAN as PPI 1.220.

moregan added a commit to moregan/PPI that referenced this issue Nov 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants