Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the PerlX-QuoteOperator CPAN distribution.

Report information
The Basics
Id: 72822
Status: resolved
Priority: 0/
Queue: PerlX-QuoteOperator

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

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



Subject: Effective bracketting is inconvenient.
Say I define a quote operator qURL as: sub ($) { URI->new($_[0]) } Then the following: qURL(http://www.google.com/)->authority is not intepreted as: qURL( q(http://www.google.com/) )->authority but as: qURL( q(http://www.google.com/)->authority ) ... which is annoying.
Hi TOBYINK, Yes it is annoying :( However as described in the "HOW DOES IT DO IT?" section of the POD this is the expected outcome because I'm letting the Perl parser do all the work and simply performing the most basic "keyhole surgery" squeezing in necessary function call before the quote-like operator. So for your line... qURL(http://www.google.com/)->authority .. the parsing is in essence inserting a " q" between qURL and parenthesis so that it becomes.... qURL q(http://www.google.com/)->authority So definitely annoying but at least you know the Perl parser is doing all the heavy lifting and not my module! To get around "the problem" you either have help the Perl parser.... ( qURL(http://www.google.com/) )->authority ... or use the -parser option. This kicks in my own simple parser which adds parenthesis around function & quote-like operator and should be fine as long as you keep your quote- like operator usage to one line! Many thanks for the RT. I've updated the CAVEAT section and it also prompted me to add () & {} to the alternative parser to that your example can actually work :) chars Barry
I hadn't been able to get the alternative parser to work - probably down to the lack of () and {} support. So your improvements to the parser will certainly help. I've attached a patch to improve the parser still further, adding <> and [] as pairs of quote characters, and using Text::Balanced to parse any bracketed quotes. This allows, for example: qURL[http://example.com/geo?coord[0]=1&coord[1]=30]; to work. Note the square brackets used within the URL itself! This is similar to how Perl's built-in quote characters work.
Subject: pxqo-text_balanced.diff
--- /usr/lib/perl5/site_perl/5.10.1/PerlX/QuoteOperator.orig 2011-12-01 04:58:28.029617064 +0000 +++ /usr/lib/perl5/site_perl/5.10.1/PerlX/QuoteOperator.pm 2011-12-01 05:23:24.224367869 +0000 @@ -4,6 +4,7 @@ use 5.008001; use Devel::Declare (); +use Text::Balanced (); use base 'Devel::Declare::Context::Simple'; our $VERSION = '0.03'; @@ -54,9 +55,18 @@ if ( $self->{ $parser } ) { # find start & end of quote operator - my $pos = $self->offset; # position just after "http" - my $delim = _closing_delim( substr( $line, $pos, 1 ) ); - do { $pos++ } until substr( $line, $pos, 1 ) eq $delim; + my $pos = $self->offset; # position just after "http" + my $opener = substr( $line, $pos, 1 ); + my $closer = _closing_delim( $opener ); + if ($closer eq $opener) { + do { $pos++ } until substr( $line, $pos, 1 ) eq $closer; + } + else { + my $text = substr($line, $pos); + my ($capture, $remaining) = Text::Balanced::extract_bracketed($text, $opener); + $pos += length $capture; + $pos--; + } # and wrap sub() around quote operator (needed for lists) substr( $line, $pos + 1, 0 ) = ')'; @@ -80,6 +90,8 @@ my $d = shift; return ')' if $d eq '('; return '}' if $d eq '{'; + return ']' if $d eq '['; + return '>' if $d eq '<'; return $d; } @@ -92,11 +104,6 @@ PerlX::QuoteOperator - Create new quote-like operators in Perl -=head1 VERSION - -Version 0.02 - - =head1 SYNOPSIS Create a quote-like operator which convert text to uppercase:
On Thu Dec 01 00:38:04 2011, TOBYINK wrote: Show quoted text
> I hadn't been able to get the alternative parser to work - probably down > to the lack of () and {} support. So your improvements to the parser will > certainly help.
Sorry about that :( Though in my defence it was mentioned in the POD that it only matched on same delimiter :) Show quoted text
> I've attached a patch to improve the parser still further, adding <> and > [] as pairs of quote characters, and using Text::Balanced to parse any > bracketed quotes. This allows, for example: > > qURL[http://example.com/geo?coord[0]=1&coord[1]=30]; > > to work. Note the square brackets used within the URL itself! This is > similar to how Perl's built-in quote characters work.
You learn something new everyday! I'd always thought that q & qq would barf on something like this!! So happy to add your Text::Balanced patch. However before I do would you prefer to wrap this up in a Github fork/pull request? Your call?? chars Barry PS: Github repo: https://github.com/draegtun/PerlX-QuoteOperator
On 2011-12-01T09:52:36Z, DRAEGTUN wrote: Show quoted text
> So happy to add your Text::Balanced patch. However before I do would > you prefer to wrap > this up in a Github fork/pull request? Your call??
I try to avoid git as much as possible.
Sorry for the delay. I've now applied your patch to 0.04 which I've just uploaded to CPAN. Thanks, Barry