From: Matt S Trout Date: Thu, 26 Jul 2007 22:32:41 +0000 (+0000) Subject: latest updates X-Git-Tag: 0.005000~134 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=323ae557f7cdab8861315cd7fc67dd31b26dbfcf;p=p5sagit%2FDevel-Declare.git latest updates --- diff --git a/Makefile.PL b/Makefile.PL index 09df2f6..e2aec53 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -3,6 +3,7 @@ use inc::Module::Install 0.67; name 'Devel-Declare'; all_from 'lib/Devel/Declare.pm'; +requires 'Scalar::Util'; build_requires 'Test::More'; WriteMakefile( diff --git a/lib/Devel/Declare.pm b/lib/Devel/Declare.pm index 707f3e1..db54af1 100644 --- a/lib/Devel/Declare.pm +++ b/lib/Devel/Declare.pm @@ -15,6 +15,7 @@ use constant DECLARE_PACKAGE => 8+1; # name implicit use vars qw(%declarators %declarator_handlers); use base qw(DynaLoader); +use Scalar::Util 'set_prototype'; bootstrap Devel::Declare; @@ -111,6 +112,35 @@ sub done_declare { } } +sub build_sub_installer { + my ($class, $pack, $name, $proto) = @_; + return eval " + package ${pack}; + my \$body; + sub ${name} (${proto}) :lvalue {\n" + .'$body->(@_); + }; + sub { ($body) = @_; };'; +} + +sub setup_declarators { + my ($class, $pack, $to_setup) = @_; + die "${class}->setup_declarator(\$pack, \\\%to_setup)" + unless defined($pack) && ref($to_setup eq 'HASH'); + foreach my $name (keys %$to_setup) { + my $info = $to_setup->{$name}; + my $flags = $info->{flags} || DECLARE_NAME; + my $run = $info->{run}; + my $compile = $info->{compile}; + my $proto = $info->{proto} || '&'; + my $sub_proto = $proto; + # make all args optional to enable lvalue for DECLARE_NONE + $sub_proto =~ s/;//; $sub_proto = ';'.$sub_proto; + my $installer = $class->build_sub_installer($pack, $name, $proto); + # XXX UNCLEAN + } +} + =head1 NAME Devel::Declare -