I've a similar need. However, I do not want to create a module, since the
function I need to call is already inside a module. All I want to do is:
#Create a logger object and log a message using log4perl
#call the function and check the $retval
#if $retval == 1 $logger->info("Test succeded")
#else $logger->warn( "Test failed" )
I've a bunch of such scenarios and I wish to have them in files like 0.t,
1.t, 2.t....
and read the file names from my MANIFEST file. I tried using the
Test::Harness, however Test::Harness does not allow variables to passed on
to the scripts executed. As you can gather I am building a Test suite using
Perl and would like to reuse mechanism used to test perl modules. In short I
want to do something like:
#main.pl
#loop through MANIFEST and read contents into @tests
#runtests from @tests
#0.t
sub test1 {
my ( $foo ) = shift;
#initialize logger object
#call a function from module bar::somebar
#if success log success
#if failure log failure
}
The key requirement is that the .t files must capable of acquiring values
from main.pl. Is this possible?
Thanks
Rajesh
-----Original Message-----
From: drieux [mailto:[EMAIL PROTECTED]
Sent: Friday, November 14, 2003 1:37 PM
To: begin begin
Subject: Re: external sub routine
On Friday, Nov 14, 2003, at 18:38 US/Pacific, David Inglis wrote:
> I have a some code that will be used in a number of my scripts, I know
> that if I have a sub in a script I can call that piece of code as many
> times as required from the same script but how do I make this sub
> vailable to other scripts I have written. I imagine that I create a
> seperate script with this code and somehow include this or call it.
What you will ultimately want to do is
move on to creating your first Perl Module.
I have my general rant on PM's at:
<http://www.wetware.com/drieux/CS/lang/Perl/PM/>
it of course suggests that you visit
<http://www.wetware.com/drieux/CS/Proj/PID/>
where I show how to use h2xs, where it show you at
<http://www.wetware.com/drieux/CS/Proj/PID/#TheTypeScript>
the output of the h2xs and the basic form of a perl
module that it will create.
you will of course want to read
perldoc perlsub Perl subroutines
perlmod Perl modules: how they work
perlmodlib Perl modules: how to write and use
perlmodinstall Perl modules: how to install from CPAN
the other strategy is to go with perl's OO-ish approach
and that would start out a bit simpler in template form
package Foo::Bar;
use 5.006;
use strict;
use warnings;
our $VERSION = '0.01';
sub new
{
my $type = shift;
my $class = ref($type) || $type;
my $self = {};
bless $self, $class;
} # end of our simple new
#---------------------------------
# so that AUTOLOAD finds one here
sub DESTROY {}
#
# your methods here
#
1; # so that the 'use Foo::Bar' will know we are happy
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]