[libtest-bdd-cucumber-perl] 22/52: Step files may now be localized: step definition functions are aliased
Intrigeri
intrigeri at moszumanska.debian.org
Thu Jun 19 10:18:34 UTC 2014
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to annotated tag 0.19
in repository libtest-bdd-cucumber-perl.
commit c87e6fcfcbd5847803f046943487caf719921a59
Author: glauschwuffel <glauschwuffel at nomaden.org>
Date: Mon May 26 21:17:59 2014 +0200
Step files may now be localized: step definition functions are aliased
---
lib/Test/BDD/Cucumber/StepFile.pm | 42 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/lib/Test/BDD/Cucumber/StepFile.pm b/lib/Test/BDD/Cucumber/StepFile.pm
index 5cdb46b..2912cb3 100755
--- a/lib/Test/BDD/Cucumber/StepFile.pm
+++ b/lib/Test/BDD/Cucumber/StepFile.pm
@@ -10,9 +10,10 @@ use strict;
use warnings;
use Carp qw/croak/;
+use Test::BDD::Cucumber::I18n qw(languages langdef);
require Exporter;
our @ISA = qw(Exporter);
-our @EXPORT = qw(Given When Then Step Transform Before After C S);
+our @EXPORT = qw(Givenn When Then Step Transform Before After C S Angenommen);
our @definitions;
@@ -77,6 +78,45 @@ sub Transform { push( @definitions, [ Transform => @_ ] ) }
sub Before { push( @definitions, [ Before => @_ ] ) }
sub After { push( @definitions, [ After => @_ ] ) }
+my @SUBS;
+
+for my $language (languages()) {
+ # skip English since these are the function we alias
+ next if $language eq 'en';
+
+ my $langdef=langdef($language);
+
+ _alias_function( $langdef->{given}, \&Given);
+ _alias_function( $langdef->{when}, \&When);
+ _alias_function( $langdef->{then}, \&Then);
+
+# Hm ... in cucumber, all step definining keywords are the same.
+# Here, the parser replaces 'and' and 'but' with the last verb. Tricky ...
+# _alias_function( $langdef->{and}, \&And);
+# _alias_function( $langdef->{but}, \&But);
+}
+
+push @EXPORT, @SUBS;
+
+sub _alias_function {
+ my ($keywords, $f)=@_;
+
+ my @keywords=split('\|', $keywords);
+ for my $word (@keywords) {
+ next if $word eq '[*]';
+ # remove non-word characters
+ $word =~ s{[^\p{Word}]}{}g;
+
+ no strict 'refs';
+ no warnings 'redefine';
+ *$word=$f;
+ use warnings 'redefine';
+
+ push @SUBS, $word;
+ use strict 'refs';
+ }
+}
+
=head2 C
=head2 S
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtest-bdd-cucumber-perl.git
More information about the Pkg-perl-cvs-commits
mailing list