This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Optimise %hash in sub { %hash || ... }
[perl5.git] / ext / B / B / Concise.pm
index 26fb34d..3f2a93d 100644 (file)
@@ -14,7 +14,7 @@ use warnings; # uses #3 and #4, since warnings uses Carp
 
 use Exporter (); # use #5
 
-our $VERSION   = "0.90";
+our $VERSION   = "0.92";
 our @ISA       = qw(Exporter);
 our @EXPORT_OK = qw( set_style set_style_standard add_callback
                     concise_subref concise_cv concise_main
@@ -137,7 +137,7 @@ sub concise_subref {
     my $codeobj = svref_2object($coderef);
 
     return concise_stashref(@_)
-       unless ref $codeobj eq 'B::CV';
+       unless ref($codeobj) =~ '^B::(?:CV|FM)\z';
     concise_cv_obj($order, $codeobj, $name);
 }
 
@@ -356,22 +356,30 @@ sub compile {
            }
            else {
                # convert function names to subrefs
-               my $objref;
                if (ref $objname) {
                    print $walkHandle "B::Concise::compile($objname)\n"
                        if $banner;
-                   $objref = $objname;
+                   concise_subref($order, ($objname)x2);
+                   next;
                } else {
                    $objname = "main::" . $objname unless $objname =~ /::/;
-                   print $walkHandle "$objname:\n";
                    no strict 'refs';
-                   unless (exists &$objname) {
+                   my $glob = \*$objname;
+                   unless (*$glob{CODE} || *$glob{FORMAT}) {
+                       print $walkHandle "$objname:\n" if $banner;
                        print $walkHandle "err: unknown function ($objname)\n";
                        return;
                    }
-                   $objref = \&$objname;
+                   if (my $objref = *$glob{CODE}) {
+                       print $walkHandle "$objname:\n" if $banner;
+                       concise_subref($order, $objref, $objname);
+                   }
+                   if (my $objref = *$glob{FORMAT}) {
+                       print $walkHandle "$objname (FORMAT):\n"
+                           if $banner;
+                       concise_subref($order, $objref, $objname);
+                   }
                }
-               concise_subref($order, $objref, $objname);
            }
        }
        for my $pkg (@render_packs) {
@@ -621,6 +629,7 @@ $priv{$_}{16} = "OURINTR" for ("gvsv", "rv2sv", "rv2av", "rv2hv", "r2gv",
        "enteriter");
 $priv{$_}{8} = 'LVSUB' for qw(rv2av rv2gv rv2hv padav padhv aelem helem
                         aslice hslice av2arylen keys rkeys substr pos vec);
+$priv{$_}{64} = 'BOOL' for 'rv2hv', 'padhv';
 $priv{substr}{16} = 'REPL1ST';
 $priv{$_}{16} = "TARGMY"
   for (map(($_,"s$_"),"chop", "chomp"),
@@ -635,8 +644,8 @@ $priv{$_}{16} = "TARGMY"
        "exec", "kill", "getppid", "getpgrp", "setpgrp", "getpriority",
        "setpriority", "time", "sleep");
 $priv{$_}{4} = "REVERSED" for ("enteriter", "iter");
-@{$priv{"const"}}{2,4,8,16,64} =
-    ("NOVER","SHORT","STRICT","ENTERED","BARE");
+@{$priv{"const"}}{2,4,8,16,64,128} =
+    ("NOVER","SHORT","STRICT","ENTERED","BARE","FOLD");
 $priv{"flip"}{64} = $priv{"flop"}{64} = "LINENUM";
 $priv{"list"}{64} = "GUESSED";
 $priv{"delete"}{64} = "SLICE";
@@ -1129,7 +1138,8 @@ on threaded and un-threaded perls.
 =head1 OPTIONS
 
 Arguments that don't start with a hyphen are taken to be the names of
-subroutines to render; if no such functions are specified, the main
+subroutines or formats to render; if no
+such functions are specified, the main
 body of the program (outside any subroutines, and not including use'd
 or require'd files) is rendered.  Passing C<BEGIN>, C<UNITCHECK>,
 C<CHECK>, C<INIT>, or C<END> will cause all of the corresponding