* Perl gurus: why do we need Scalar::Util? @ 2006-07-10 11:44 Johannes Schindelin 2006-07-10 13:00 ` Petr Baudis 2006-07-10 13:28 ` Perl gurus: why do we need Scalar::Util? Randal L. Schwartz 0 siblings, 2 replies; 10+ messages in thread From: Johannes Schindelin @ 2006-07-10 11:44 UTC (permalink / raw) To: git Hi, please do not let my die dumb: what is this "blessed" thing all about? And why do we need it in the private-Error.pm?? Thanks, Dscho ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Perl gurus: why do we need Scalar::Util? 2006-07-10 11:44 Perl gurus: why do we need Scalar::Util? Johannes Schindelin @ 2006-07-10 13:00 ` Petr Baudis 2006-07-11 0:53 ` [PATCH] Eliminate Scalar::Util usage from private-Error.pm Petr Baudis 2006-07-10 13:28 ` Perl gurus: why do we need Scalar::Util? Randal L. Schwartz 1 sibling, 1 reply; 10+ messages in thread From: Petr Baudis @ 2006-07-10 13:00 UTC (permalink / raw) To: Johannes Schindelin; +Cc: git Hi, Dear diary, on Mon, Jul 10, 2006 at 01:44:39PM CEST, I got a letter where Johannes Schindelin <Johannes.Schindelin@gmx.de> said that... > please do not let my die dumb: what is this "blessed" thing all about? And > why do we need it in the private-Error.pm?? I'm working on it. I'll try to get a patch together by the evening. -- Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Snow falling on Perl. White noise covering line noise. Hides all the bugs too. -- J. Putnam ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] Eliminate Scalar::Util usage from private-Error.pm 2006-07-10 13:00 ` Petr Baudis @ 2006-07-11 0:53 ` Petr Baudis 2006-07-11 1:38 ` Randal L. Schwartz 2006-07-11 1:57 ` Junio C Hamano 0 siblings, 2 replies; 10+ messages in thread From: Petr Baudis @ 2006-07-11 0:53 UTC (permalink / raw) To: Junio C Hamano; +Cc: git We used just the blessed() routine so steal it from Scalar/Util.pm. ;-) (Unfortunately, Scalar::Util is not bundled with older Perl versions.) Signed-off-by: Petr Baudis <pasky@suse.cz> --- perl/private-Error.pm | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/perl/private-Error.pm b/perl/private-Error.pm index ebd0749..848e82b 100644 --- a/perl/private-Error.pm +++ b/perl/private-Error.pm @@ -43,8 +43,6 @@ sub throw_Error_Simple # Exported subs are defined in Error::subs -use Scalar::Util (); - sub import { shift; local $Exporter::ExportLevel = $Exporter::ExportLevel + 1; @@ -290,6 +288,20 @@ use vars qw(@EXPORT_OK @ISA %EXPORT_TAGS @ISA = qw(Exporter); + +# Stolen from Scalar::Util: + +# Hope nobody defines a sub by this name +sub UNIVERSAL::a_sub_not_likely_to_be_here { ref($_[0]) } + +sub blessed ($) { + local($@, $SIG{__DIE__}, $SIG{__WARN__}); + length(ref($_[0])) + ? eval { $_[0]->a_sub_not_likely_to_be_here } + : undef +} + + sub run_clauses ($$$\@) { my($clauses,$err,$wantarray,$result) = @_; my $code = undef; @@ -312,7 +324,7 @@ sub run_clauses ($$$\@) { $i -= 2; next CATCHLOOP; } - elsif(Scalar::Util::blessed($err) && $err->isa($pkg)) { + elsif(blessed($err) && $err->isa($pkg)) { $code = $catch->[$i+1]; while(1) { my $more = 0; @@ -421,7 +433,7 @@ sub try (&;$) { if (defined($err)) { - if (Scalar::Util::blessed($err) && $err->can('throw')) + if (blessed($err) && $err->can('throw')) { throw $err; } ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm 2006-07-11 0:53 ` [PATCH] Eliminate Scalar::Util usage from private-Error.pm Petr Baudis @ 2006-07-11 1:38 ` Randal L. Schwartz 2006-07-11 1:40 ` Randal L. Schwartz 2006-07-11 1:57 ` Junio C Hamano 1 sibling, 1 reply; 10+ messages in thread From: Randal L. Schwartz @ 2006-07-11 1:38 UTC (permalink / raw) To: Petr Baudis; +Cc: Junio C Hamano, git >>>>> "Petr" == Petr Baudis <pasky@suse.cz> writes: Petr> We used just the blessed() routine so steal it from Scalar/Util.pm. ;-) Petr> (Unfortunately, Scalar::Util is not bundled with older Perl versions.) Wow. That's sure the long way around for what I would use this for: sub blessed { my $item = shift; local $@; # don't kill an outer $@ ref $item and eval { $item->can('can') }; } We call it "doing the can-can". :) And this solution has the advantage that it doesn't pollute UNIVERSAL. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm 2006-07-11 1:38 ` Randal L. Schwartz @ 2006-07-11 1:40 ` Randal L. Schwartz 2006-07-11 1:42 ` Randal L. Schwartz 0 siblings, 1 reply; 10+ messages in thread From: Randal L. Schwartz @ 2006-07-11 1:40 UTC (permalink / raw) To: Petr Baudis; +Cc: Junio C Hamano, git >>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes: Randal> sub blessed { Randal> my $item = shift; Randal> local $@; # don't kill an outer $@ Randal> ref $item and eval { $item->can('can') }; Randal> } Oops, lose the local $@ line. Just found out this is a broken thing in current Perls. The rest is good though. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm 2006-07-11 1:40 ` Randal L. Schwartz @ 2006-07-11 1:42 ` Randal L. Schwartz 0 siblings, 0 replies; 10+ messages in thread From: Randal L. Schwartz @ 2006-07-11 1:42 UTC (permalink / raw) To: Petr Baudis; +Cc: Junio C Hamano, git >>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes: >>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes: Randal> sub blessed { Randal> my $item = shift; Randal> local $@; # don't kill an outer $@ Randal> ref $item and eval { $item->can('can') }; Randal> } Randal> Oops, lose the local $@ line. Just found out this is a broken Randal> thing in current Perls. The rest is good though. And thirdly, ignore what I *just* said, and concentrate on what I *previously* said, becaused my testing was off. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm 2006-07-11 0:53 ` [PATCH] Eliminate Scalar::Util usage from private-Error.pm Petr Baudis 2006-07-11 1:38 ` Randal L. Schwartz @ 2006-07-11 1:57 ` Junio C Hamano 2006-07-11 3:38 ` Randal L. Schwartz 1 sibling, 1 reply; 10+ messages in thread From: Junio C Hamano @ 2006-07-11 1:57 UTC (permalink / raw) To: Petr Baudis; +Cc: git Petr Baudis <pasky@suse.cz> writes: > We used just the blessed() routine so steal it from Scalar/Util.pm. ;-) > (Unfortunately, Scalar::Util is not bundled with older Perl versions.) Eh, but aren't we going to rip out the try{}catch{} stuff to avoid extra closures? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm 2006-07-11 1:57 ` Junio C Hamano @ 2006-07-11 3:38 ` Randal L. Schwartz 0 siblings, 0 replies; 10+ messages in thread From: Randal L. Schwartz @ 2006-07-11 3:38 UTC (permalink / raw) To: Junio C Hamano; +Cc: Petr Baudis, git >>>>> "Junio" == Junio C Hamano <junkio@cox.net> writes: Junio> Petr Baudis <pasky@suse.cz> writes: >> We used just the blessed() routine so steal it from Scalar/Util.pm. ;-) >> (Unfortunately, Scalar::Util is not bundled with older Perl versions.) Junio> Eh, but aren't we going to rip out the try{}catch{} stuff to Junio> avoid extra closures? Heh. Yeah, didn't notice that. I keep cutting down the trees, but the forest remains. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Perl gurus: why do we need Scalar::Util? 2006-07-10 11:44 Perl gurus: why do we need Scalar::Util? Johannes Schindelin 2006-07-10 13:00 ` Petr Baudis @ 2006-07-10 13:28 ` Randal L. Schwartz 2006-07-10 14:29 ` Petr Baudis 1 sibling, 1 reply; 10+ messages in thread From: Randal L. Schwartz @ 2006-07-10 13:28 UTC (permalink / raw) To: Johannes Schindelin; +Cc: git >>>>> "Johannes" == Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: Johannes> please do not let my die dumb: what is this "blessed" thing all about? And Johannes> why do we need it in the private-Error.pm?? Ugh. Just took a peek for the first time at the "next" branch, and I see the dangerous syntactic-sugar try { } catch { }. Sorry for not noticing that earlier. While that syntax looks like it would make things easier in theory, in practice it is a source of leak-after-leak because it creates a closure for the two blocks, and that can easily lead to a circular reference for long-running tools. This would be of some concern if someone writes a mod_perl module or a standalone webserver that doesn't exec itself to clean up (which it shouldn't need). So, if there's going to be rewrite, the first part would be to eliminate the try { } catch { } sugar, and replace it with more traditional exception catchers. eval { }; if ($@) { ... } Note that I'm *not* suggesting not to use Error.pm - that's a great means by which to create hierarchical error classes that stringify nicely and carry context on the error. I'm just saying to throw out the try/catch syntax helper. Sorry about that. If it's any consequence, we got it right in Perl 6. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Perl gurus: why do we need Scalar::Util? 2006-07-10 13:28 ` Perl gurus: why do we need Scalar::Util? Randal L. Schwartz @ 2006-07-10 14:29 ` Petr Baudis 0 siblings, 0 replies; 10+ messages in thread From: Petr Baudis @ 2006-07-10 14:29 UTC (permalink / raw) To: Randal L. Schwartz; +Cc: Johannes Schindelin, git Dear diary, on Mon, Jul 10, 2006 at 03:28:49PM CEST, I got a letter where "Randal L. Schwartz" <merlyn@stonehenge.com> said that... > While that syntax looks like it would make things easier in theory, in > practice it is a source of leak-after-leak because it creates a closure for > the two blocks, and that can easily lead to a circular reference for > long-running tools. Care to elaborate, please? All I've found are several mentions that the problem is there, but not what the problem actually is and it doesn't occur to me why is it a problem. -- Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Snow falling on Perl. White noise covering line noise. Hides all the bugs too. -- J. Putnam ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-07-11 3:38 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-07-10 11:44 Perl gurus: why do we need Scalar::Util? Johannes Schindelin 2006-07-10 13:00 ` Petr Baudis 2006-07-11 0:53 ` [PATCH] Eliminate Scalar::Util usage from private-Error.pm Petr Baudis 2006-07-11 1:38 ` Randal L. Schwartz 2006-07-11 1:40 ` Randal L. Schwartz 2006-07-11 1:42 ` Randal L. Schwartz 2006-07-11 1:57 ` Junio C Hamano 2006-07-11 3:38 ` Randal L. Schwartz 2006-07-10 13:28 ` Perl gurus: why do we need Scalar::Util? Randal L. Schwartz 2006-07-10 14:29 ` Petr Baudis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).