Skip Menu |

This queue is for tickets about the Text-Balanced CPAN distribution.

Report information
The Basics
Id: 74994
Status: open
Priority: 0/
Queue: Text-Balanced

People
Owner: Nobody in particular
Requestors: maik.hentsche [...] amd.com
Cc:
AdminCc:

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



Subject: stringification is overloaded but comparison is not.
When a Text::Balanced function generates an error and I compare $@ to '' afterwards I get the following error (see attached example program: Operation "ne": no method found, left argument in overloaded package Text::Balanced::ErrorMsg, right argument has no overloaded magic at /tmp/autoload line 7. This is obviously because cmp is not overloaded. Since "" is overloaded I think cmp should be overloaded too. The attached patch implements this.
Subject: example_program_cmp_issue.pl
use Text::Balanced 'extract_delimited'; use strict; use warnings; my $text = 'while($a == "test"){ print "true";}'; my ($extracted, $reminder) = extract_delimited($text, '#' ); print $@ if '' ne $@;
Subject: overload_cmp.patch
diff --git a/lib/Text/Balanced.pm b/lib/Text/Balanced.pm index 07d9567..dff2c6a 100644 --- a/lib/Text/Balanced.pm +++ b/lib/Text/Balanced.pm @@ -1019,6 +1019,7 @@ sub extract($$) # ($self, $text) package Text::Balanced::ErrorMsg; use overload '""' => sub { "$_[0]->{error}, detected at offset $_[0]->{pos}" }; +use overload 'cmp' => sub { $_[0]->{error} cmp $_[1] }; 1;
On Tue Feb 14 07:52:28 2012, maik.hentsche@amd.com wrote: Show quoted text
> When a Text::Balanced function generates an error and I compare $@ to '' > afterwards I get the following error (see attached example program: > > Operation "ne": no method found, > left argument in overloaded package Text::Balanced::ErrorMsg, > right argument has no overloaded magic at /tmp/autoload line 7. > > This is obviously because cmp is not overloaded. Since "" is overloaded I > think cmp should be overloaded too. The attached patch implements this.
Is there a reason the patch has not been applied? repo location?
You should also add fallback=>1 to your overload options, so the existing overloads can be used, where possible, to fill in for all the others that aren't defined.
In the meantime this workaround should help. # hacky workaround for desperate folk # intended to be copypasted into your app { require Text::Balanced; require overload; local $@; # this is what poisons $@ Text::Balanced::extract_bracketed( '(foo', '()' ); if ( $@ and overload::Overloaded($@) and !overload::Method( $@, 'fallback' ) ) { my $class = ref $@; eval "package $class; overload->import(fallback => 1);"; } } http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/DBIx-Class.git;a=commitdiff;h=153a6b389e6886920ff69ce0dab0ea7ee1df2fe0