--- /dev/null
+package SQL;
+use lib 'lib/';
+use Keyword qw/debug/;
+use DBI;
+use Carp;
+use Data::Dumper;
+
+our $DBH;
+
+keyword SELECT (sql) {
+ confess "no database connection set" unless $DBH;
+ return $DBH->selectrow_hashref($sql);
+}
+
+parse sql($kd) {
+ my $sql = $kd->strip_to_char(';');
+ $kd->terminate;
+ return $sql;
+}
+
+action sql ($sql) {
+ return "SELECT $sql";
+}
+
+sub CONNECT {
+ $DBH = DBI->connect(@_);
+};
+
+1;
my $b = 1 if $proto =~ /block/i;
my $parser = Keyword::Parser->new({proto=>$proto,
- module=>$KW_MODULE, noblock=>$b, keyword=>$keyword});
+ module=>$KW_MODULE, block=>$b, keyword=>$keyword});
no strict 'refs';
*{$KW_MODULE."::import"} = mk_import($parser->build, $keyword, $b);
};
}
else {
+ no strict 'refs';
*{$module_user."::$keyword"} = sub {
- $Keyword::__keyword_block_ret; };
+ &$Keyword::__keyword_block(@Keyword::__keyword_block_arg);
+ };
}
};
}
for my $pa (@{$self->{plist}}) {
push @arg, $self->exec($pa);
}
-
- &{$Keyword::__keyword_block}(@arg);
+
+ # if it has a block execute keyword block at compile
+ if($self->{block}) {
+ &{$Keyword::__keyword_block}(@arg);
+ }
+ else { # no block execute at runtime, save arg
+ @Keyword::__keyword_block_arg = @arg;
+ }
};
}
--- /dev/null
+use Test::More qw/no_plan/;
+use strict;
+use warnings;
+use lib 'examples/';
+use SQL;
+use Data::Dumper;
+
+ok 1;
+
+SQL::CONNECT("dbi:Pg:dbname=humus;host=localhost;port=5432");
+
+my $r = SELECT * FROM TRACK;
+
+diag Dumper $r;
+#ok ($r);
+
+ok 1;