Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the PPI CPAN distribution.

Report information
The Basics
Id: 31564
Status: open
Priority: 0/
Queue: PPI

People
Owner: Nobody in particular
Requestors: TELS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.201
Fixed in: (no value)



Subject: How to create a PPI::Structure::Condition
Download (untitled) / with headers
text/plain 1.6k
Since PPI leaves of the Structure::Condition and Statement::Expression when parsing things like "if $a == 9" (note the lack of "()" around the expression!), I wanted to re-insert them into the tree, so that my code deals with the tree later is simplified to only one variant. Aka I want to turn: PPI::Document PPI::Statement::Break PPI::Token::Word 'return' PPI::Token::Word 'if' PPI::Token::Symbol '$a' PPI::Token::Operator '==' PPI::Token::Number '0' Into this: PPI::Document PPI::Statement::Break PPI::Token::Word 'return' PPI::Token::Word 'if' PPI::Structure::Condition ( ... ) PPI::Statement::Expression PPI::Token::Symbol '$a' PPI::Token::Operator '==' PPI::Token::Number '0' For this, I need to create a "PPI::Structure::Condition" and insert it after the "if". So, naturally you do: # Add a PPI::Structure::Condition my $Token = PPI::Structure::Condition->new(); and try to insert it. Except it doesn't work. After some very very long struggles with creating this object, I found exactly one way (partially by reading the source of Lexer.pm) this seems to work: # Add a PPI::Structure::Condition my $Token = PPI::Structure::Condition->new( PPI::Token::Structure->new('('), ); $Token->{finish} = PPI::Token::Structure->new(')'); This however violates the OO convention because it access internal data (the "->{finish}" part). So I'd like to have an easier way to create PPI::Structure::Condition elements, and this should also be documented (the POD for PPI::Structure::Condition is useless in its current form).
Subject: Re: [rt.cpan.org #31564] How to create a PPI::Structure::Condition
Date: Tue, 18 Dec 2007 11:25:56 +1100
To: bug-PPI [...] rt.cpan.org
From: "Adam Kennedy" <adamkennedybackup [...] gmail.com>
Download (untitled) / with headers
text/plain 2.2k
Any API recommendations? PPI::Structure::Condition->create('()'); ? On 16/12/2007, TELS via RT <bug-PPI@rt.cpan.org> wrote: Show quoted text
> > > Sat Dec 15 13:37:13 2007: Request 31564 was acted upon. > Transaction: Ticket created by TELS > Queue: PPI > Subject: How to create a PPI::Structure::Condition > Broken in: 1.201 > Severity: Wishlist > Owner: Nobody > Requestors: TELS@cpan.org > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=31564 > > > > Since PPI leaves of the Structure::Condition and Statement::Expression > when parsing things like "if $a == 9" (note the lack of "()" around the > expression!), I wanted to re-insert them into the tree, so that my code > deals with the tree later is simplified to only one variant. Aka I want > to turn: > > PPI::Document > PPI::Statement::Break > PPI::Token::Word 'return' > PPI::Token::Word 'if' > PPI::Token::Symbol '$a' > PPI::Token::Operator '==' > PPI::Token::Number '0' > > Into this: > > PPI::Document > PPI::Statement::Break > PPI::Token::Word 'return' > PPI::Token::Word 'if' > PPI::Structure::Condition ( ... ) > PPI::Statement::Expression > PPI::Token::Symbol '$a' > PPI::Token::Operator '==' > PPI::Token::Number '0' > > For this, I need to create a "PPI::Structure::Condition" and insert it > after the "if". > > So, naturally you do: > > # Add a PPI::Structure::Condition > my $Token = PPI::Structure::Condition->new(); > > and try to insert it. Except it doesn't work. > > After some very very long struggles with creating this object, I found > exactly one way (partially by reading the source of Lexer.pm) this seems > to work: > > # Add a PPI::Structure::Condition > my $Token = PPI::Structure::Condition->new( > PPI::Token::Structure->new('('), > ); > $Token->{finish} = PPI::Token::Structure->new(')'); > > This however violates the OO convention because it access internal data > (the "->{finish}" part). > > So I'd like to have an easier way to create PPI::Structure::Condition > elements, and this should also be documented (the POD for > PPI::Structure::Condition is useless in its current form). >
Subject: Re: [rt.cpan.org #31564] How to create a PPI::Structure::Condition
Date: Tue, 18 Dec 2007 13:14:26 +0100
To: bug-PPI [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
Download (untitled) / with headers
text/plain 1.1k
On Tuesday 18 December 2007 01:26:34 Adam Kennedy via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=31564 > > > Any API recommendations? > > PPI::Structure::Condition->create('()'); ?
A simple: PPI::Structure::Condition->new(); should do the trick, defaulting to "()", because that makes it consistent with all the other Nodes/Elements. For the other cases ("{" and "["), it would really simplify code if you could do: my $Token = PPI::Structure::Condition->new( '(' ); my $Token = PPI::Structure::Condition->new( '{' ); my $Token = PPI::Structure::Condition->new( '[' ); Optionally '()' and the second character gets ignored, as the "(" and ")" need to match, anyway. That way you don't need to remember and write the lenghty my $Token = PPI::Structure::Condition->new( PPI::Token::Structure->new('('), ); Does this make sense? All the best, Tels -- Signed on Tue Dec 18 13:09:16 2007 with key 0x93B84C15. View my photo gallery: http://bloodgate.com/photos PGP key on http://bloodgate.com/tels.asc or per email. "To be beautiful is enough! If a woman can do that well who should demand more from her? You don't want a rose to sing." -- Thackeray
Download (untitled)
application/pgp-signature 481b

Message body not shown because it is not plain text.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.