+ABOUT
+This module aims to provide an easy to use interface to Devel::Declare.
+
+If you haven't heard of DD, you have probably been sitting under a rock for the few months, I suggest you take a look at the following modules:
+
+Devel::Develare
+http://search.cpan.org/~flora/Devel-Declare-0.005011/lib/Devel/Declare.pm
+
+MooseX::Declare
+http://search.cpan.org/~flora/MooseX-Declare-0.32/lib/MooseX/Declare.pm
+
+I really don't know what I am doing, so all feedback / abuse is welcome
+
TODO
-* write more tests and examples
+* write more tests, docs and examples
+* cleanup parser construction (check if code exists etc)
+* write default action to return whatever the parse routine matched
SYNTAX
#parse an action routines called for each entry in proto
#passed a Keyword::Parser object
parse custom ($parser) {
+ if (my $len = $parser->scan_word(1)) {
+ my $l = $parser->line;
+ my $ident = substr($l, $parser->offset, $len);
+ substr($l, $parser->offset, $len) = '';
+ $parser->line($l);
+ return $ident if $ident =~ /^[a-z]{1}\w+$/i;
+ }
+ else {
+ die "unable to match blah";
+ }
}
#passed whatever the parse routine matches
return $code;
}
-INFO
+YADDA
<mst> rob: hey, we were talking about this
<mst> basically, the answer is to standardise the declaration forms
<mst> so you have something like
$block->terminate;
}
-sub action_ident { shift; } # return method name
-sub action_proto {
- my $proto = shift;
+action proto ($proto) {
$proto =~ s/\s//g;
$proto = "\$self,$proto" if length($proto);
return " my ($proto) = \@_; ";
}
+# return method name
+action ident ($ident) {
+ return $ident;
+}
+
+
1;
substr($l, $parser->offset+1, 0) = $code;
$parser->line($l);
- no strict 'refs';
- no warnings 'redefine';
- warn $name;
- *{$KW_MODULE.'::action'} = sub (&) {
- warn $name;
+ $parser->shadow("$KW_MODULE\::action", sub (&) {
+ no strict 'refs';
*{$KW_MODULE."::action_$name"} = shift;
- };
+ });
}
sub eos {
=head2 Parse routines
-There 3 built-in parse routines:
+There are three built-in parse routines:
ident - matches an identifier
proto - matches anything surrounded by parenthese
block - matches the start of a block
+Its possible to write your own with the following syntax:
+
+ parse something($parser) {
+ if (my $len = $parser->scan_word(1)) {
+ my $l = $parser->line;
+ my $ident = substr($l, $parser->offset, $len);
+ substr($l, $parser->offset, $len) = '';
+ $parser->line($l);
+ return $ident if $ident =~ /^[a-z]{1}\w+$/i;
+ }
+ }
+
+=head3 Blocks
+
+A block is different from a standard parse routine as it returns an object.
+
+This object contains several routines for injecting code into the block:
+
+ $block->name($identifier);
+ $block->code("some(); code();"); # no newlines please
+ $block->terminate; # adds semicolon
+
=cut
=head2 Actions
-Actions get passed whatever its parse routine matches and return directly
+Actions get passed whatever the associated parse routine 'matches'.
+
+There job is to convert whatever is matched to injectable perl code.
=cut
=head1 CODE
+http://github.com/robinedwards/Keyword
+
git@github.com:robinedwards/Keyword.git
=head1 AUTHOR
#set name as global for import;
no strict 'refs';
- ${$self->package."::__block_name"} = $name;
+ ${$self->package."::__block_name"} = $name;
+
unless ($sub) {
if($name) {
$sub = sub (&) {
}
parse_thing();
+action_thing();
ok 1;