git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Eliminate Scalar::Util usage from private-Error.pm

From
Petr Baudis <pasky@suse.cz>
Date
Jul 11, 2006, 00:53 UTC
Message-ID
<20060711005354.5911.62525.stgit@machine.or.cz>
In-Reply-To
<20060710130046.GW29115@pasky.or.cz>

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;
         }
Previous: Petr BaudisNext: Randal L. Schwartz
Message 3 of 10 in “Perl gurus: why do we need Scalar::Util?”
  1. Johannes SchindelinJul 10, 2006
  2. Petr BaudisJul 10, 2006
  3. Eliminate Scalar::Util usage from private-Error.pmPetr Baudis, Jul 11, 2006
  4. Randal L. SchwartzJul 11, 2006
  5. Randal L. SchwartzJul 11, 2006
  6. Randal L. SchwartzJul 11, 2006
  7. Junio C HamanoJul 11, 2006
  8. Randal L. SchwartzJul 11, 2006
  9. Randal L. SchwartzJul 10, 2006
  10. Petr BaudisJul 10, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.