{"thread":{"id":"4829","subject":"Perl gurus: why do we need Scalar::Util?","startedAt":"2006-07-10T11:44:39Z","lastAt":"2006-07-11T03:38:13Z","messageCount":10,"participants":["Johannes Schindelin","Petr Baudis","Randal L. Schwartz","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"23539","messageId":"Pine.LNX.4.63.0607101343060.29667@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4829","inReplyTo":null,"subject":"Perl gurus: why do we need Scalar::Util?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-07-10T11:44:39Z","receivedAt":"2006-07-10T11:44:39Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nplease do not let my die dumb: what is this \"blessed\" thing all about? And \nwhy do we need it in the private-Error.pm??\n\nThanks,\nDscho\n"},{"id":"23544","messageId":"20060710130046.GW29115@pasky.or.cz","threadId":"4829","inReplyTo":"Pine.LNX.4.63.0607101343060.29667@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: Perl gurus: why do we need Scalar::Util?","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-07-10T13:00:46Z","receivedAt":"2006-07-10T13:00:46Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"  Hi,\n\nDear diary, on Mon, Jul 10, 2006 at 01:44:39PM CEST, I got a letter\nwhere Johannes Schindelin <Johannes.Schindelin@gmx.de> said that...\n> please do not let my die dumb: what is this \"blessed\" thing all about? And \n> why do we need it in the private-Error.pm??\n\n  I'm working on it. I'll try to get a patch together by the evening.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nSnow falling on Perl. White noise covering line noise.\nHides all the bugs too. -- J. Putnam\n"},{"id":"23549","messageId":"86k66lsi5q.fsf@blue.stonehenge.com","threadId":"4829","inReplyTo":"Pine.LNX.4.63.0607101343060.29667@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: Perl gurus: why do we need Scalar::Util?","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-07-10T13:28:49Z","receivedAt":"2006-07-10T13:28:49Z","isPatch":false,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Johannes\" == Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\nJohannes> please do not let my die dumb: what is this \"blessed\" thing all about? And \nJohannes> why do we need it in the private-Error.pm??\n\nUgh.  Just took a peek for the first time at the \"next\" branch, and I see the\ndangerous syntactic-sugar try { } catch { }.  Sorry for not noticing that\nearlier.\n\nWhile that syntax looks like it would make things easier in theory, in\npractice it is a source of leak-after-leak because it creates a closure for\nthe two blocks, and that can easily lead to a circular reference for\nlong-running tools.  This would be of some concern if someone writes\na mod_perl module or a standalone webserver that doesn't exec itself\nto clean up (which it shouldn't need).\n\nSo, if there's going to be rewrite, the first part would be to eliminate\nthe try { } catch { } sugar, and replace it with more traditional\nexception catchers.\n\n        eval { };\n        if ($@) { ... }\n\nNote that I'm *not* suggesting not to use Error.pm - that's a great\nmeans by which to create hierarchical error classes that stringify nicely\nand carry context on the error.  I'm just saying to throw out the\ntry/catch syntax helper.\n\nSorry about that.  If it's any consequence, we got it right in Perl 6. :)\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"23551","messageId":"20060710142916.GX29115@pasky.or.cz","threadId":"4829","inReplyTo":"86k66lsi5q.fsf@blue.stonehenge.com","subject":"Re: Perl gurus: why do we need Scalar::Util?","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-07-10T14:29:16Z","receivedAt":"2006-07-10T14:29:16Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Mon, Jul 10, 2006 at 03:28:49PM CEST, I got a letter\nwhere \"Randal L. Schwartz\" <merlyn@stonehenge.com> said that...\n> While that syntax looks like it would make things easier in theory, in\n> practice it is a source of leak-after-leak because it creates a closure for\n> the two blocks, and that can easily lead to a circular reference for\n> long-running tools.\n\nCare to elaborate, please? All I've found are several mentions that the\nproblem is there, but not what the problem actually is and it doesn't\noccur to me why is it a problem.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nSnow falling on Perl. White noise covering line noise.\nHides all the bugs too. -- J. Putnam\n"},{"id":"23605","messageId":"20060711005354.5911.62525.stgit@machine.or.cz","threadId":"4829","inReplyTo":"20060710130046.GW29115@pasky.or.cz","subject":"[PATCH] Eliminate Scalar::Util usage from private-Error.pm","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-07-11T00:53:54Z","receivedAt":"2006-07-11T00:53:54Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"We used just the blessed() routine so steal it from Scalar/Util.pm. ;-)\n(Unfortunately, Scalar::Util is not bundled with older Perl versions.)\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/private-Error.pm |   20 ++++++++++++++++----\n 1 files changed, 16 insertions(+), 4 deletions(-)\n\ndiff --git a/perl/private-Error.pm b/perl/private-Error.pm\nindex ebd0749..848e82b 100644\n--- a/perl/private-Error.pm\n+++ b/perl/private-Error.pm\n@@ -43,8 +43,6 @@ sub throw_Error_Simple\n \n # Exported subs are defined in Error::subs\n \n-use Scalar::Util ();\n-\n sub import {\n     shift;\n     local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;\n@@ -290,6 +288,20 @@ use vars qw(@EXPORT_OK @ISA %EXPORT_TAGS\n \n @ISA = qw(Exporter);\n \n+\n+# Stolen from Scalar::Util:\n+\n+# Hope nobody defines a sub by this name\n+sub UNIVERSAL::a_sub_not_likely_to_be_here { ref($_[0]) }\n+\n+sub blessed ($) {\n+    local($@, $SIG{__DIE__}, $SIG{__WARN__});\n+    length(ref($_[0]))\n+        ? eval { $_[0]->a_sub_not_likely_to_be_here }\n+        : undef\n+}\n+\n+\n sub run_clauses ($$$\\@) {\n     my($clauses,$err,$wantarray,$result) = @_;\n     my $code = undef;\n@@ -312,7 +324,7 @@ sub run_clauses ($$$\\@) {\n \t\t    $i -= 2;\n \t\t    next CATCHLOOP;\n \t\t}\n-\t\telsif(Scalar::Util::blessed($err) && $err->isa($pkg)) {\n+\t\telsif(blessed($err) && $err->isa($pkg)) {\n \t\t    $code = $catch->[$i+1];\n \t\t    while(1) {\n \t\t\tmy $more = 0;\n@@ -421,7 +433,7 @@ sub try (&;$) {\n \n     if (defined($err))\n     {\n-        if (Scalar::Util::blessed($err) && $err->can('throw'))\n+        if (blessed($err) && $err->can('throw'))\n         {\n             throw $err;\n         }\n"},{"id":"23606","messageId":"86bqrwncnq.fsf@blue.stonehenge.com","threadId":"4829","inReplyTo":"20060711005354.5911.62525.stgit@machine.or.cz","subject":"Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-07-11T01:38:49Z","receivedAt":"2006-07-11T01:38:49Z","isPatch":true,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Petr\" == Petr Baudis <pasky@suse.cz> writes:\n\nPetr> We used just the blessed() routine so steal it from Scalar/Util.pm. ;-)\nPetr> (Unfortunately, Scalar::Util is not bundled with older Perl versions.)\n\nWow.  That's sure the long way around for what I would use this for:\n\nsub blessed {\n        my $item = shift;\n        local $@; # don't kill an outer $@\n        ref $item and eval { $item->can('can') };\n}\n\nWe call it \"doing the can-can\". :)\n\nAnd this solution has the advantage that it doesn't pollute UNIVERSAL.\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"23607","messageId":"867j2knckf.fsf@blue.stonehenge.com","threadId":"4829","inReplyTo":"86bqrwncnq.fsf@blue.stonehenge.com","subject":"Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-07-11T01:40:48Z","receivedAt":"2006-07-11T01:40:48Z","isPatch":true,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Randal\" == Randal L Schwartz <merlyn@stonehenge.com> writes:\n\nRandal> sub blessed {\nRandal>         my $item = shift;\nRandal>         local $@; # don't kill an outer $@\nRandal>         ref $item and eval { $item->can('can') };\nRandal> }\n\nOops, lose the local $@ line.  Just found out this is a broken\nthing in current Perls.  The rest is good though.\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"23608","messageId":"863bd8nchg.fsf@blue.stonehenge.com","threadId":"4829","inReplyTo":"867j2knckf.fsf@blue.stonehenge.com","subject":"Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-07-11T01:42:35Z","receivedAt":"2006-07-11T01:42:35Z","isPatch":true,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Randal\" == Randal L Schwartz <merlyn@stonehenge.com> writes:\n\n>>>>> \"Randal\" == Randal L Schwartz <merlyn@stonehenge.com> writes:\nRandal> sub blessed {\nRandal> my $item = shift;\nRandal> local $@; # don't kill an outer $@\nRandal> ref $item and eval { $item->can('can') };\nRandal> }\n\nRandal> Oops, lose the local $@ line.  Just found out this is a broken\nRandal> thing in current Perls.  The rest is good though.\n\nAnd thirdly, ignore what I *just* said, and concentrate on what I *previously*\nsaid, becaused my testing was off.\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"23609","messageId":"7v4pxo7vk4.fsf@assigned-by-dhcp.cox.net","threadId":"4829","inReplyTo":"20060711005354.5911.62525.stgit@machine.or.cz","subject":"Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-07-11T01:57:15Z","receivedAt":"2006-07-11T01:57:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n> We used just the blessed() routine so steal it from Scalar/Util.pm. ;-)\n> (Unfortunately, Scalar::Util is not bundled with older Perl versions.)\n\nEh, but aren't we going to rip out the try{}catch{} stuff to\navoid extra closures?\n"},{"id":"23611","messageId":"86y7v0lska.fsf@blue.stonehenge.com","threadId":"4829","inReplyTo":"7v4pxo7vk4.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Eliminate Scalar::Util usage from private-Error.pm","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-07-11T03:38:13Z","receivedAt":"2006-07-11T03:38:13Z","isPatch":true,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Junio\" == Junio C Hamano <junkio@cox.net> writes:\n\nJunio> Petr Baudis <pasky@suse.cz> writes:\n>> We used just the blessed() routine so steal it from Scalar/Util.pm. ;-)\n>> (Unfortunately, Scalar::Util is not bundled with older Perl versions.)\n\nJunio> Eh, but aren't we going to rip out the try{}catch{} stuff to\nJunio> avoid extra closures?\n\nHeh.  Yeah, didn't notice that.  I keep cutting down the trees,\nbut the forest remains. :)\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"}]}