From: Robin Edwards Date: Thu, 18 Feb 2010 21:08:52 +0000 (+0000) Subject: some refactoring in KD X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=27e91c74bb2a0f3cc988f617b8bdde2ac25e0230;p=p5sagit%2FDevel-Declare-Keyword.git some refactoring in KD - added pod test - updated README --- diff --git a/README b/README index 7dac14a..bc34fb5 100644 --- a/README +++ b/README @@ -3,30 +3,27 @@ This module aims to provide an easy interface to Devel::Declare. EXAMPLES SQL.pm - execute select statements in perl -Methods.pm - +Methods.pm - usual method signature PLAN * add support for multiple keywords per module -* let modules optionally write there own import subs -* find usescases from: http://cpants.perl.org/dist/used_by/Devel-Declare -* and go through perl's -existing- keywords print $fh "sddfsd". $f, $c etc -* look at ... metalua ... and common lisp reader macros. - * remove globals * write pod for Keyword::Declare - * cleanup parser construction (check if code exists etc) * write default action to return whatever the parse routine matched - -* add pre and post block hooks with shadow { setup_shit() ;exec_block(); do_shit; return $ret} - -* alter sig syntax to: +* add pre and post block hooks with shadow { setup_stuff() ;exec_block(); do_stuff; return $ret} +* alter sig syntax to (see MXD code) keyword method (Maybe[Ident] $ident, Maybe[Proto] $proto, Block $block) { +RESEARCH +* find usescases from: http://cpants.perl.org/dist/used_by/Devel-Declare +* and go through perl's -existing- keywords print $fh "sddfsd". $f, $c etc +* look at ... metalua ... and common lisp reader macros. * long term goal, a hints file describing syntax to be shared with ppi / vim etc + CURRENT SYNTAX -#parse an action routines called for each entry in proto +# parse an action routines called for each entry in proto keyword method (ident?, proto?, custom, block) { $block->name($ident); # name the block $block->inject_begin($proto); # inject at begin of block @@ -34,7 +31,7 @@ keyword method (ident?, proto?, custom, block) { $block->terminate; # add semi colon } -#passed a Keyword::Declare object +# passed a Keyword::Declare object parse custom ($parser) { if (my $len = $parser->scan_word(1)) { my $l = $parser->line; @@ -48,7 +45,7 @@ parse custom ($parser) { } } -#passed whatever the parse routine matches +# passed whatever the parse routine matches action proto ($match) { my $match; return $code; diff --git a/examples/SQL.pm b/examples/SQL.pm index bc772cc..50a745e 100644 --- a/examples/SQL.pm +++ b/examples/SQL.pm @@ -1,10 +1,12 @@ package SQL; use lib 'lib/'; -use Keyword qw/debug/; +use Keyword; use DBI; use Carp; use Data::Dumper; +sub import { install_keyword_SELECT();}; + our $DBH; keyword SELECT (sql) { diff --git a/lib/Keyword.pm b/lib/Keyword.pm index f5130c1..ea7961d 100644 --- a/lib/Keyword.pm +++ b/lib/Keyword.pm @@ -41,8 +41,7 @@ sub import { #parses keyword signature sub keyword_parser { - warn Dumper @_; #need to pass @_ to KD - my $kd = Keyword::Declare->new; + my $kd = Keyword::Declare->new(@_); $kd->next_token; $kd->skip_ws; @@ -75,7 +74,7 @@ sub keyword_parser { # parses the parse keyword sub parse_parser { - my $kd = Keyword::Declare->new; + my $kd = Keyword::Declare->new(@_); $kd->next_token; $kd->skip_ws; @@ -102,7 +101,7 @@ sub parse_parser { # parses the action keyword sub action_parser { - my $kd = Keyword::Declare->new; + my $kd = Keyword::Declare->new(@_); $kd->next_token; $kd->skip_ws; diff --git a/lib/Keyword/Declare.pm b/lib/Keyword/Declare.pm index 7ddeda4..8bf8e64 100644 --- a/lib/Keyword/Declare.pm +++ b/lib/Keyword/Declare.pm @@ -3,6 +3,7 @@ use strict; use warnings; use Carp; use Devel::Declare; +use Data::Dumper; =head1 NAME @@ -19,11 +20,10 @@ Keyword::Declare - simple oo interface to Devel::Declare sub new { - my ($class, $self) = @_; - $self = {} unless $self; - no strict 'refs'; - $self->{offset} = 0; - bless($self,__PACKAGE__); + my ($class) = @_; + my $self->{offset} = $_[2] || 0; + $self->{declarator} = $_[1]; + bless($self,$class); } =head1 METHODS @@ -40,6 +40,11 @@ sub offset { return $self->{offset}; } +sub declarator { + my $self = shift; + return $self->{declarator} +} + =head2 inc_offset increments the current offset diff --git a/lib/Keyword/Parser.pm b/lib/Keyword/Parser.pm index d2cb840..9aa4a7c 100644 --- a/lib/Keyword/Parser.pm +++ b/lib/Keyword/Parser.pm @@ -23,9 +23,9 @@ sub build { my $self = shift; $self->_build_ident_list; $self->_lookup_routines; - $self->declare(Keyword::Declare->new); return sub { + $self->declare(Keyword::Declare->new(@_)); my @arg; $self->declare->skip_to($self->{keyword}); diff --git a/t/pod.t b/t/pod.t new file mode 100644 index 0000000..daee2ef --- /dev/null +++ b/t/pod.t @@ -0,0 +1,6 @@ +use strict; +use warnings; +use Test::More; +eval "use Test::Pod 1.00"; +plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; +all_pod_files_ok()