From: Robin Edwards Date: Thu, 17 Dec 2009 16:52:23 +0000 (+0000) Subject: now uses carp X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=109b501769e673f55503e09f41f0e47db4a1d745;p=p5sagit%2FDevel-Declare-Keyword.git now uses carp --- diff --git a/README b/README index c31d0aa..e2aab40 100644 --- a/README +++ b/README @@ -6,7 +6,6 @@ PLAN * and go through perl's -existing- keywords print $fh "sddfsd". $f, $c etc * look at ... metalua ... and common lisp reader macros. -* use carp * remove globals * write pod for Keyword::Declare diff --git a/lib/Keyword.pm b/lib/Keyword.pm index d1ae5dd..d486d0a 100644 --- a/lib/Keyword.pm +++ b/lib/Keyword.pm @@ -1,6 +1,7 @@ package Keyword; use strict; use warnings; +use Carp; use Devel::Declare; use B::Hooks::EndOfScope; use Data::Dumper; @@ -45,13 +46,13 @@ sub keyword_parser { #strip out the name of new keyword my $keyword = parse_ident($kd) or - die "expecting identifier for keyword near:\n".$kd->line; + croak "expecting identifier for keyword near:\n".$kd->line; $kd->skip_ws; #extract the prototype my $proto = parse_proto($kd) or - die "expecting prototype for keyword at:\n".$kd->line; + croak "expecting prototype for keyword at:\n".$kd->line; my $parser = Keyword::Parser->new({proto=>$proto, module=>$KW_MODULE}); @@ -76,11 +77,11 @@ sub parse_parser { #strip out the name of parse routine my $name = parse_ident($kd) or - die "expecting identifier for parse near:\n".$kd->line; + croak "expecting identifier for parse near:\n".$kd->line; $kd->skip_ws; my $proto = parse_proto($kd) or - die "expecting prototype for parse at:\n".$kd->line; + croak "expecting prototype for parse at:\n".$kd->line; $kd->skip_ws; my $l = $kd->line; @@ -103,11 +104,11 @@ sub action_parser { #strip out the name of action my $name = parse_ident($kd) or - die "expecting identifier for action near:\n".$kd->line; + croak "expecting identifier for action near:\n".$kd->line; $kd->skip_ws; my $proto = parse_proto($kd) or - die "expecting prototype for action at:\n".$kd->line; + croak "expecting prototype for action at:\n".$kd->line; $kd->skip_ws; my $l = $kd->line; diff --git a/lib/Keyword/Parser.pm b/lib/Keyword/Parser.pm index 3764fa4..b3a9a02 100644 --- a/lib/Keyword/Parser.pm +++ b/lib/Keyword/Parser.pm @@ -1,6 +1,7 @@ package Keyword::Parser; use strict; use warnings; +use Carp; use Keyword::Declare; our %BUILTIN = ( @@ -11,8 +12,8 @@ our %BUILTIN = ( sub new { my ($class, $self) = @_; - $self->{proto} or die 'no proto provided'; - $self->{module} or die 'no module provided'; + $self->{proto} or croak 'no proto provided'; + $self->{module} or croak 'no module provided'; bless($self,$class); } @@ -47,7 +48,7 @@ sub exec { my ($self, $pa) = @_; my $match = &{$pa->{parse}}($self->declare); $self->declare->skip_ws; - die "failed to parse $pa->{name}" unless $match or $pa->{opt}; + croak "failed to parse $pa->{name}" unless $match or $pa->{opt}; return &{$pa->{action}}($match); } @@ -57,7 +58,7 @@ sub _build_ident_list { my @i = split /\,/, $self->{proto}; for my $ident (@i){ $ident =~ /^[a-z]{1}\w+[\?]?$/i or - die "bad identifier '$ident' in prototype."; + croak "bad identifier '$ident' in prototype."; my $opt; $ident =~ s/\?//g and $opt = 1 if $ident =~ /\?$/; push @{$self->{plist}}, {name=>lc($ident),optional=>$opt};