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
Data::Dumper 2.101 and qr// #800
Comments
From michael@shoebox.netData::Dumper 2.101 has a problem with qr// objects, in that it dies when it The patch is a little ugly, mostly due to the fact that qr// objects are odd Michael === patch === Inline Patchdiff -u Data-Dumper-2.101-orig/Dumper.pm Data-Dumper-2.101/Dumper.pm
--- Data-Dumper-2.101-orig/Dumper.pm Fri Apr 30 17:29:35 1999
+++ Data-Dumper-2.101/Dumper.pm Sun Oct 31 17:42:26 1999
@@ -221,7 +221,15 @@
($realpack, $realtype, $id) =
(overload::StrVal($val) =~ /^(?:(.*)\=)?([^=]*)\(([^\(]*)\)$/);
-
+
+ if ($type eq 'Regexp' && $val =~ /^\(?/) {
+ # assume this is a qr// pre-compiled regex and short-circuit things
+ my $re = $val;
+ $re =~ s/'/\\'/g;
+ return "qr'$re'";
+ }
+
+
# if it has a name, we need to either look it up, or keep a tab
# on it so we know when we hit it later
if (defined($name) and length($name)) {
diff -u Data-Dumper-2.101-orig/Dumper.xs Data-Dumper-2.101/Dumper.xs
--- Data-Dumper-2.101-orig/Dumper.xs Fri Apr 30 17:28:17 1999
+++ Data-Dumper-2.101/Dumper.xs Mon Nov 1 15:18:00 1999
@@ -175,10 +175,49 @@
realtype = SvTYPE(ival);
(void) sprintf(id, "0x%lx", (unsigned long)ival);
idlen = strlen(id);
- if (SvOBJECT(ival))
+ if (SvOBJECT(ival)) {
realpack = HvNAME(SvSTASH(ival));
- else
+
+ if (SvMAGICAL(ival)
+ &&
+ strEQ(realpack, "Regexp")
+ &&
+ mg_find(ival, 'r')
+ ) {
+ char *re_str;
+ char *re_qstr;
+ I32 sq = 0; /* number of single quotes */
+ STRLEN re_len = 0;
+ STRLEN re_qlen;
+ int i;
+
+ re_str = SvPV(val, re_len);
+
+ for (i = 0; i < re_len; i++)
+ if (re_str[i] == '\'') sq++;
+
+ New(0, re_qstr, re_len + sq + 1, char);
+
+ for (i = 0, re_qlen = 0; i < re_len; i++, re_qlen++) {
+ if (re_str[i] == '\'')
+ re_qstr[re_qlen++] = '\\';
+ re_qstr[re_qlen] = re_str[i];
+ }
+
+ re_qstr[re_qlen + 1] = '\0';
+
+ sv_setpv (retval, "qr'");
+ sv_catpvn(retval, re_qstr, re_qlen);
+ sv_catpv (retval, "'");
+
+ Safefree(re_qstr);
+
+ return 1;
+ }
+
+ } else {
realpack = Nullch;
+ }
/* if it has a name, we need to either look it up, or keep a tab
* on it so we know when we hit it later Perl Info
|
From [Unknown Contact. See original ticket]Michael Fowler writes:
This matches always. Ilya |
From @vanstynIn <199911020158.UAA23217@monk.mps.ohio-state.edu>, Ilya Zakharevich writes: Note that with _62: I think the above test gets it right in that case, at least. Perhaps we need the concept of 'reserved packages', but at least things Even better would be, as discussed before, two new tests: the package Hugo |
From [Unknown Contact. See original ticket]Hugo writes:
I repeat: the =~ test as written is a NOOP. Ilya |
From [Unknown Contact. See original ticket]On Mon, Nov 01, 1999 at 08:58:00PM -0500, Ilya Zakharevich wrote:
Oops, it should be: + if ($type eq 'Regexp' && $val =~ /^\(\?/) { A fixed version of the patch is at www.shoebox.net/perl/Data-Dumper-qr.patch. Michael |
From @vanstynIn <199911020223.VAA23333@monk.mps.ohio-state.edu>, Ilya Zakharevich writes: Sorry, my mistake. Hugo |
From @gsarOn Mon, 01 Nov 1999 15:52:55 -0900, Michael Fowler wrote:
You need to fix overload.pm to get that right. See these for how it was ftp://ftp.linux.activestate.com/pub/staff/gsar/APC/5.005_58/diffs/3570.gz Sarathy |
From [Unknown Contact. See original ticket]:The patch is a little ugly, mostly due to the fact that qr// objects are odd How does one recreate a qr// object at run-time from XS without constructing I'm asking just in case someone wishes to have Storable handle that kind Raphael |
From [Unknown Contact. See original ticket]Hi, Raphael Manfredi:
Umm.. you don't?
I'd _really_ like to see Storable do that, too. My application is a bunch of processes which send messages to each other, On a related note, Perl should simplify regexp flags.
Then again, I could write a regexp to simplify the regexp. :-) -- |
From @gsarOn Tue, 02 Nov 1999 10:46:16 +0100, Raphael Manfredi wrote:
FWIW, I'm totally uncomfortable with the "design" of these Regexp These things are neither true Perl objects (in the sense that I'd much rather than they were straight objects (owned by re::?) Sarathy |
From @TimToadyGurusamy Sarathy writes: A number of other things should work that way too. Exceptions, Larry |
From [Unknown Contact. See original ticket]
IIRC, it was done this way as a temporary measure. What was really If we can solve that, maybe with a special SV type or something, then Graham. Sarathy |
From [Unknown Contact. See original ticket]Graham Barr wrote, in part:
Allowing 'use overload'ed objects to have an assignment overload There's a fairly amusing explanation of why '=' does not really
With overloads, it can be a reference blessed in to re::. re:: Yes, that'd be slower than a special SV, but it would pave the way And then any speedups applied to this mechanism might then improve FWIW, Barrie P.S. That's amusing in a positive sense :-). |
From @gsarOn Wed, 10 Nov 1999 07:40:43 CST, "Graham Barr" wrote:
I have no problem with it being a blessed reference. My issues are * there's no namespace called "Regexp" anywhere that provides the * the stringify overload is totally invisible and behind-the-scenes. This leads to very surprising behavior because ref() says one thing Sarathy |
From @TimToadyBarrie Slaymaker writes: I don't know about assignment overloading, but I'd agree that we need And as Sarathy just pointed out, we need to make these internal objects I think the definition of an internal object is something like Larry |
From [Unknown Contact. See original ticket]Larry Wall wrote, in part:
Me either :-). Overloaded designs are tricky enough to begin Without being able to overload assignment, you can build an There are more assignments done in most stretches of Perl than Having it be shallow is a hard gotcha for people to remember, If it feels like a scalar most of the time you're using it, it's I do know the tie workaround, and it's an awkward departure I'm not advocating heavy use of operator overloading here, but I suspect that it's hard to do or it would have been implemented - Barrie |
From [Unknown Contact. See original ticket]Barrie Slaymaker writes:
Being slower will not pay anything. But my deliberations braught me But we leave the special case for stringification of a REx in sv.c. Ilya |
From [Unknown Contact. See original ticket]Gurusamy Sarathy writes:
Hmm? Are not you confused about the scope and semantic of no overload Ilya |
From [Unknown Contact. See original ticket]Barrie Slaymaker <barries@slaysys.com> writes: But what is the meaning of overloaded assignment? In my $x = 1; # $x has an integer value you don't expect the second assignment to be affected by the Overloading assignment only makes sense in a strongly typed While writing the book, I hit upon a trick to do a type-specific my $product = $arg - $arg + 1; # 1, but int/BigInt/etc: same as $arg -- |
From [Unknown Contact. See original ticket]On Wed, Nov 10, 1999 at 09:30:51PM -0500, John Macdonald wrote:
Which Perl became now (at least enough to make overloading assignment Ilya |
From [Unknown Contact. See original ticket]John Macdonald wrote:
And that's a clear statement of the problem. It all hinges on It would allow people to make simple-as-a-scalar APIs. Consider: my $x = 1 ; ... much code passes ... $y += 1 ; ${x}'s old contents are _not_ replaced by ${y}'s contents ('11'), $y->internal( 2 ) ; ## not a public API, but you get my point some time later, in a module far, far away, and the value of $x What I'm proposing is an overloaded assignment operator In my simple way, I'm thinking of something like: ---------8<------------ use overload "assign" => \&assign ; ... sub assign { ---------8<------------ So: my $a = MyInt->new( 6 ) ; my $b = $a ; ## calls MyInt::assign( $a ) print "$a $b\n" ; would yield the least surprising (IMO) output "5 6\n" and leave $a That's necessarily as powerful a metaphor as you get when the type If you want something more like a strongly typed language, then - weak typing, - 'clingy' typing, which allows the target to try to - a poor man's strong typing, only checked at run time and all at the author's discretion. ---------8<------------ use overload "assign" => \&assign ; use Carp ; ## Set $mode to 'weak', 'clingy', or 'strong' ... sub assign { ## Assume similar code in package MyOtherInt. ---------8<------------ Then: my $a = MyInt->new( 6 ) ; $b = $a ; ## calls MyOtherInt::assign( $b, $a ) print "$a $b\n" ; Would output "5 6\n" and leave the types of $a and $b alone. It's late. I'm probably ignoring something here. Ignorance is And this all may be a bit much, especially if assignment overloading's - Barrie |
Migrated from rt.perl.org#1727 (status was 'resolved')
Searchable as RT1727$
The text was updated successfully, but these errors were encountered: