From: Robin Edwards <robin.ge@gmail.com>
Date: Mon, 14 Dec 2009 14:34:53 +0000 (+0000)
Subject: added debug
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5b7afe2d4f0569008f8f3fb2e629463f1217e269;p=p5sagit%2FDevel-Declare-Keyword.git

added debug
---

diff --git a/README b/README
index feb1d2b..ba43c43 100644
--- a/README
+++ b/README
@@ -53,7 +53,7 @@ action proto ($match) {
 	return $code;
 }
 
-YADDA
+IRC
 <mst> rob: hey, we were talking about this
 <mst> basically, the answer is to standardise the declaration forms
 <mst> so you have something like
diff --git a/examples/Methods.pm b/examples/Methods.pm
index 4db63f4..badcc10 100644
--- a/examples/Methods.pm
+++ b/examples/Methods.pm
@@ -1,6 +1,6 @@
 package Methods;
 use lib 'lib/';
-use Keyword;
+use Keyword qw/debug/;
 use Data::Dumper;
 
 keyword method (ident?, proto?, block) {
diff --git a/lib/Keyword.pm b/lib/Keyword.pm
index 2895889..d831fbd 100644
--- a/lib/Keyword.pm
+++ b/lib/Keyword.pm
@@ -11,9 +11,11 @@ use Keyword::Parse::Ident;
 
 our $VERSION = '0.03';
 our $KW_MODULE = caller;
+our $DEBUG = 0;
 
 #setup parser for keyword syntax
 sub import {
+	$DEBUG = 1 if $_[1] =~ /debug/i;
 
 	Devel::Declare->setup_for(
 		$KW_MODULE,
@@ -94,7 +96,6 @@ sub parse_parser {
 		no strict 'refs';
 		*{$KW_MODULE."::parse_$name"} =  shift; 
 	});
-
 }
 
 # parses the action keyword
@@ -147,6 +148,7 @@ sub kw_proto_to_code {
 	return $inject;
 }
 
+sub debug { warn @_ if $DEBUG; }
 
 #converts prototype to a list of parse and action subs
 sub proto_to_parselist {
@@ -163,7 +165,7 @@ sub proto_to_parselist {
 		my $opt;
 		$ident =~ s/\?//g and $opt = 1 if $ident =~ /\?$/;
 
-		my $p = {ident=>$ident, opt=>$opt};
+		my $p = {name=>$ident, opt=>$opt};
 		no strict 'refs';
 		if($ident eq 'ident') {
 			$p->{parse} = \&{'Keyword::Parse::Ident::parse_ident'};
@@ -194,8 +196,9 @@ sub mk_parser {
 	my ($plist,$keyword) = @_;
 	return sub {
 		my $parser = Keyword::Parser->new;
-		$parser->next_token; # skip keyword
+		$parser->next_token;
 		$parser->skip_ws;
+
 		my @arg;
 
 		#call each parse routine and action
@@ -203,7 +206,8 @@ sub mk_parser {
 			#TODO: add evals
 			my $match = &{$r->{parse}}($parser); 
 			$parser->skip_ws;
-			die "failed to match parse action  $r->{name}" unless $match or $r->{opt};
+			die "failed to match parse action $r->{name}" unless $match or $r->{opt};
+			debug("matched '$match' for $r->{name}");
 			push @arg, &{$r->{action}}($match);
 		}
 
diff --git a/lib/Keyword/Parser.pm b/lib/Keyword/Parser.pm
index 8e6559f..5b45c66 100644
--- a/lib/Keyword/Parser.pm
+++ b/lib/Keyword/Parser.pm
@@ -2,7 +2,6 @@ package Keyword::Parser;
 use strict;
 use warnings;
 use Devel::Declare;
-use Data::Dumper;
 
 sub new {
 	my ($class, $self) = @_;