[Pdx-pm] deparse question

Kris Bosland krisb at ring.org
Mon Aug 8 17:31:35 PDT 2005


	Guys, I am trying to make a short, flexible perl find that I can
use in in Win32.

My basic premise:
	1. First argument is user control, rest is dirs
	2. Eval user control and check ref
		2.a. if scalar, make into Regexp
		2.b. if Regexp, make default CODE printing filename if
			match
		2.c. if CODE, use as find sub
		2.d. if other ref, complain
	3. Find on dirs with sub

Anyway, for debugging, I want to deparse the sub I create or get.  Can I
send a CODE to B::Deparse, instead of the whole program?

Thanks.

-Kris


=================================================================
#!/usr/$work/bin/perl -w
use strict;
use File::Find;

#Collect arguments
die "usage: $0 <pattern or perl code> [directories]"
    if not @ARGV or $ARGV[0] =~ /^-[h?]/i;
my $rawmatch = shift;
my @dirs = @ARGV || ('.');

#Create match sub, or use users match sub
my $out = '$File::Find::name\n';
my $match = eval $rawmatch;
my $sub;

#Turn strings into regexp
$match = qr/$match/ if ref $match eq '';
$match = sub { eval "print $out;" } if ref $match eq 'Regexp';
die qq{Cannot handle type } . ref $match .
    qq{:"$rawmatch", only types ""(scalar), "Regexp", and "CODE"}
    if ref $match ne 'CODE';

#Execute find
find($match, @dirs);
=================================================================




More information about the Pdx-pm-list mailing list