[Pdx-pm] mini language for PPI

Eric Wilhelm scratchcomputing at gmail.com
Sun Feb 25 04:44:38 PST 2007


Anybody looked at Perl::MinimumVersion?  It's interesting, but appears 
to be headed toward the same embedded knowledge that Module::ScanDeps 
is stuck in.  Me thinks it should load data files in order to acquire 
rules more quickly.

The nice thing about PMV is that it uses PPI ("I Parse Perl"), which 
gives you a PDOM.  So, if you were designing a DSL for PDOM, what would 
it look like?  xpath?

An example:

a list of checks:
		_perl_5005_modules    => version->new('5.005'),
 ...
	my $check = List::Util::first { $self->$_()    }
	            sort { $CHECKS{$b} <=> $CHECKS{$a} }
	            grep { $CHECKS{$_}  >  $filter     }
	            keys %CHECKS;
and then the sub (err, method: the $_ up --^ there)

  sub _perl_5005_modules {
	shift->Document->find_any( sub {
		$_[1]->isa('PPI::Statement::Include')
		and
		$_[1]->module
		and (
			$_[1]->module eq 'Tie::Array'
			or
			$_[1]->module =~ /\bException\b/
			or
			$_[1]->module =~ /\bThread\b/
			or
			$_[1]->module =~ /^Error\b/
			or
			$_[1]->module eq 'base'
		)
	} );
  }

Now, it seems like something in that sub ought to be a given.  Maybe 
just less $_[1]'ing and possibly ->'ing.  Though maybe just a more 
general "use_a_module" data-driven check (ala switch.)

Also, in the case of the constant pragma hashref syntax, we need to look 
at $_[1]->schild(2) and then possibly that node (if it is a list, but 
if it is a block, that's what we were looking for) has a child of 
interest, which, if it is a "block" says that the constant.pm from 
5.6.2 (or so) won't do.

in short:
  use constant ({foo => 1});
  use constant {foo => 1};

Is a pure-perl dsl going to be expressive enough or do we just need to 
parse a string of something more tailored to the application?  Maybe 
just more standard checks and a bunch of data to drive them.  I would 
like to see PPI's find have a more concise DSL, but that's not strictly 
necessary for PMV.

Aside:  I see that user-defined pragma are available in 5.10, but I'm 
not seeing how unimport() could be automatically called when leaving 
the block.  Is that not possible?  I suppose we could take a cue from 
David (ala Class::Meta::Express) there and have the called function 
unimport.

  use pdom;
  find {
    is "foo" and whatever;
  };

Though I'm not sure that works here since is() and whatever() are still 
available after the block at compile time.  It does at least get rid of 
them as methods.

It's late, err early.

--Eric
-- 
Issues of control, repair, improvement, cost, or just plain
understandability all come down strongly in favor of open source
solutions to complex problems of any sort.
--Robert G. Brown
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------


More information about the Pdx-pm-list mailing list