Ken,
> use Inline::Select
> (Calc =>
> {Perl => sub {require 't/Calc.pm'},
> CPP => 't/Calc.cpp',
> Java => 't/Calc.java',
> Python => 't/Calc.py'});
I think this would be hard because it's possible that each of these
will have extra configuration options that would make it messy.
>
> Inline::Select->load(Calc => $ARGV[0]);
> If the load() occurs too late, it could always be wrapped in a BEGIN block.
> But I'm not too great a fan of smooshing everything into use().
Thanks for the input.
Patrick
>
> -Ken
>
>
> > -----Original Message-----
> > From: Patrick LeBoutillier [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, January 25, 2005 2:37 PM
> > To: [email protected]
> > Subject: Inline as a multi language API testing tool !?
> >
> >
> > Hi all,
> >
> > I have a Perl client for a project I'm working on these days. The API
> > for the client is really simple (1 class with new(), connect(),
> > read(), print() and close() methods). Naturally I have
> > a Perl test suite written using the standard (Test.pm in my
> > case) tools.
> >
> > Once my project was pretty much working, I realized I would need a
> > Java client, so I wrote one, using the same exact API.
> >
> > It was then that I realized that, with a few lines of Perl code and
> > Inline::Java, I could use the Perl test suite I wrote for the Perl
> > client to test the Java Client.
> >
> > I then realized that I could push it further and started writing a new
> > module, Inline::Select. It works like this:
> >
> > Suppose you have the following code, all in different languages:
> >
> > Calc.cpp:
> > class Calc {
> > public:
> > Calc() ;
> > int add(int a, int b) ;
> > } ;
> > Calc::Calc(){
> > lang = strdup("CPP") ;
> > }
> > int Calc::add(int a, int b){
> > return a + b ;
> > }
> >
> > Calc.java:
> > class Calc {
> > public Calc(){
> > }
> > public int add(int a, int b){
> > return a + b ;
> > }
> > }
> >
> > Calc.pm:
> > package Calc ;
> > sub new {
> > my $class = shift ;
> > bless({}, $class) ;
> > }
> > sub add {
> > my $this = shift ;
> > my $a = shift ;
> > my $b = shift ;
> > return $a + $b ;
> > }
> > 1 ;
> >
> > Calc.py:
> > class Calc:
> > def __init__(self) :
> > pass
> >
> > def add(self,a,b) :
> > return a + b
> >
> >
> > You could then write a test script like this:
> >
> > use strict ;
> > use warnings ;
> > use Test ;
> >
> > BEGIN {plan(tests => 1) ;}
> >
> > use Inline::Select (
> > PACKAGE => 'Calc',
> > Inline => [ Perl => sub {require 't/Calc.pm'} ]
> > ) ;
> > use Inline::Select (
> > PACKAGE => 'Calc',
> > Inline => [ CPP => 't/Calc.cpp' ]
> > ) ;
> > use Inline::Select (
> > PACKAGE => 'Calc',
> > Inline => [ Java => 't/Calc.java' ]
> > ) ;
> > use Inline::Select (
> > PACKAGE => 'Calc',
> > Inline => [ Python => 't/Calc.py' ]
> > ) ;
> >
> >
> > use Inline::Select (
> > PACKAGE => 'Calc',
> > Inline => $ARGV[0]
> > ) ;
> >
> > my $c = new Calc() ;
> > ok($c->add(2, 3), 5) ;
> >
> >
> > And then say:
> >
> > $ test.pl (Perl|Java|CPP|Python)
> >
> > The 'Calc' namespace will then be "filled in" by the approriate Inline
> > language block and the script will automatically pick up the right
> > implementation.
> >
> > The way it works is easy: Each time you "use Inline::Select" with an
> > array ref as the Inline parameter, the block is saved for later use.
> > When the Inline parameter is a scalar, that language is selected and
> > the appropriate Inline block is compiled in the caller package. The
> > PACKAGE parameter is used to identify which blocks go together.
> >
> > I'm still not sure the API is optimal but, hey, its still
> > version 0.01...
> >
> > Anyone have any comments/suggestions/anything?
> >
> >
> > Cheers,
> >
> > Patrick
> >
> > --
> > =====================
> > Patrick LeBoutllier
> > Laval, Qu�bec, Canada
> >
>
--
=====================
Patrick LeBoutllier
Laval, Qu�bec, Canada