How to get the return code of subroutines executed as standalone as command line in Perl ?
How to do I get the return code of a subroutine in a perl module if invoke the subroutine as standalone,
I have an module say TestExit.pm and in that i have a subroutine say myTest() which is returns 12, if i were to call the subroutine from
command line like
CASE:1 ( Without an explict exit in END routine )
The above statement doesnot give me the return value of the subroutine ( which is 12 ) I get exit code as 0
Where as if I explicity do an exit in the END routine I am able to get the return code properly
Case2: ( With an explict an exit in END )
Is there a way to pass an argument to the module or Is there a trick to get the exit code without modifying the END routing to an explict exit,
END routine exit is commented to get to match the case 1
TestExit.pm
Hi,
How I can get system function executed command return value ? I want to know mv command success or not ?
#include <stdio.h>
main()
{
int ret;
ret = system( "mv x.dat y.dat" );
printf( "system ret:\n", ret );
} (3 Replies)
I know how to get the returning code of a function but wonder if I can combine the follwoing two lines into one:
e.g.:
#!/bin/shell
...
#line 1
MyFunction arg1 arg 2
#line 2
rec=$? #this will be evaluated later
....
like in c/c++, we'd write one line:
rec=MyFunction(arg1, arg 2)
... (6 Replies)
i'm writing some simple scripts to help me learn perl.
why does the print command get called after the shell script is executed?
the purpose of the shell script is to simply echo to the screen "script run". which is does, but before the print command, you can clearly see the shell script is... (3 Replies)
Hi All,
Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'.
I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
I am using a perl-script from C-code, executing it by the 'system(..)' comand.
The problem is to return the perl-return code to the C correctly.
Default the 'system()' shell is Bourne: sh
My try: (perl_src.c_pl - the perl script; t_sys - C-program with system() call (I will show it... (7 Replies)
Hi everyone,
when executing this command in unix:
echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error.
here is content of my script:
tdbsrvr$ vi hc.sh
"hc.sh" 22 lines, 509... (4 Replies)
Hi
Is there any way GREP command can return word and not complete line.
My file has following data:
Hello Everyone I am NitinrajSrivastava
Hi Friends Welcome VrajSrivastava
I am using grep 'raj' which is returning me complete line.However I want only the word having keyword 'raj'.
Required... (11 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
This subroutine needs to check if there was a file name given on the command line. If so, return that. Otherwise... (1 Reply)
i want to call subroutines in perl like:
sub temp
{ ---- some code ----- }
temp(-switchName, value1, --switchName2, value2)
Like i know getoptions::Long is there for command line switches type arguments. So i want to know for subroutine type arguments. (1 Reply)
Hello all
I have a query (SQL) that returns a rather long field from an Oracle database. The field in question is defined on 400 characters but all these 400 cannot be displayed by the echo command. Thus when I launch the following command:
echo "SELECT FIELD01 FROM TABLE_NAME;" | sqlplus -s... (9 Replies)
Discussion started by: S. BASU
9 Replies
LEARN ABOUT DEBIAN
test::mockmodule
Test::MockModule(3pm) User Contributed Perl Documentation Test::MockModule(3pm)NAME
Test::MockModule - Override subroutines in a module for unit testing
SYNOPSIS
use Module::Name;
use Test::MockModule;
{
my $module = new Test::MockModule('Module::Name');
$module->mock('subroutine', sub { ... });
Module::Name::subroutine(@args); # mocked
}
Module::Name::subroutine(@args); # original subroutine
DESCRIPTION
"Test::MockModule" lets you temporarily redefine subroutines in other packages for the purposes of unit testing.
A "Test::MockModule" object is set up to mock subroutines for a given module. The object remembers the original subroutine so it can be
easily restored. This happens automatically when all MockModule objects for the given module go out of scope, or when you "unmock()" the
subroutine.
METHODS
new($package[, %options])
Returns an object that will mock subroutines in the specified $package.
If there is no $VERSION defined in $package, the module will be automatically loaded. You can override this behaviour by setting the
"no_auto" option:
my $mock = new Test::MockModule('Module::Name', no_auto => 1);
get_package()
Returns the target package name for the mocked subroutines
is_mocked($subroutine)
Returns a boolean value indicating whether or not the subroutine is currently mocked
mock($subroutine => &coderef)
Temporarily replaces one or more subroutines in the mocked module. A subroutine can be mocked with a code reference or a scalar. A
scalar will be recast as a subroutine that returns the scalar.
The following statements are equivalent:
$module->mock(purge => 'purged');
$module->mock(purge => sub { return 'purged'});
$module->mock(updated => [localtime()]);
$module->mock(updated => sub { return [localtime()]});
However, "undef" is a special case. If you mock a subroutine with "undef" it will install an empty subroutine
$module->mock(purge => undef);
$module->mock(purge => sub { });
rather than a subroutine that returns "undef":
$module->mock(purge => sub { undef });
You can call "mock()" for the same subroutine many times, but when you call "unmock()", the original subroutine is restored (not the
last mocked instance).
original($subroutine)
Returns the original (unmocked) subroutine
unmock($subroutine [, ...])
Restores the original $subroutine. You can specify a list of subroutines to "unmock()" in one go.
unmock_all()
Restores all the subroutines in the package that were mocked. This is automatically called when all "Test::MockObject" objects for the
given package go out of scope.
SEE ALSO
Test::MockObject::Extends
Sub::Override
AUTHOR
Simon Flack <simonflk _AT_ cpan.org>
COPYRIGHT
Copyright 2004 Simon Flack <simonflk _AT_ cpan.org>. All rights reserved
You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
perl v5.10.0 2005-03-24 Test::MockModule(3pm)