Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > macros: return or exit

Reply
Thread Tools

macros: return or exit

 
 
Marc Girod
Guest
Posts: n/a
 
      01-21-2010
Hello,

I consider making a change to a module, which will significantly alter
its client interface.
Until now, client functions could exit, die, or exec: no further
action was meant to take place.
Alternatively, they could return 0, and a generic behaviour would
follow.

I want now to introduce a loop, i.e. to retain control.
I control one such client, and am not sure whether there are actually
more than one other.

My problem is however to maintain a branch of the module and its known
clients, at least in order to investigate it and possibly to get
feedback. This could take a year or so. Or more.

What I did in the main loop, is:

< my $rc = &$cmd(@ARGV);
< # ... and exit unless it returned zero.
< exit $rc if $rc;
---
> my ($rc, $done) = &$cmd(@ARGV);
> # ... and return unless it returned zero and not done.
> return $rc if $done || $rc;


The change in the client code is thus ( a couple of examples out of
many):

< exit $?;
---
> return($?, 'done');


or

< $lsp->exec;
---
> return($lsp->system, 'done');


etc.
What are my best options to handle this?
I could sketch a few overrides such as e.g. for 'exit':

$legacy? exit $_ : return($_, 'done');

....but this ought to be a macro, not a function, for 'return' to
return to the right context.
What should I look for in CPAN or in the FAQ?
How to make my question shorter so that it fits in such a query?

If you are curious (you are fully entitled to), the modules are (on
CPAN):
ClearCase::Wrapper (the base module)
ClearCase::Wrapper::MGi (my own client)
ClearCase::Wrapper:SB (the other known client)

Thanks,
Marc
 
Reply With Quote
 
 
 
 
Marc Girod
Guest
Posts: n/a
 
      01-21-2010
Thanks Ben,

On Jan 21, 1:14*pm, Ben Morrow <(E-Mail Removed)> wrote:

> It's not clear what procedure you're trying to follow here. Are you
> going to create your own fork of the module, and possibly try to feed
> the changes upstream, or are you trying to find a way to avoid that?


It is not clear to me.
I'll make my choice based on the options.
If I maintain a branch, I won't publish it to CPAN: I'll keep it in my
Google Code site.
Until I have something good enough to convince the author?
Earlier if the solution is not invasive?
Never if it ends up shooting the performance down or similar.

> The syntax $cmd->(@ARGV) is usually clearer, and generalises better to
> situations like $cmd{$which}->(@ARGV).


Thanks. I agree.
I'll remember it if I push a change to the base module.

> One option is to accept that the module you are using will terminate the
> process, and fork before calling it in order to retain control. You will
> need to think carefully about whether the exit calls are going to do
> anything unpleasant to your filehandle buffers.


I don't think it is an option: I already have one fork, and I'd very
much like the forked process to remain a single shared background
server.
And it is a proprietary binary, to which I talk via stdin/stdout (I
mean that it won't 'select').

> Perl doesn't have macros, I'm afraid.


This far, I knew...

> If you can afford to maintain a fork of the module,
> a simple search-and-replace in your text editor
> would seem the easiest option.


Many nasty merges for every change I'll do...
Or generate the branched version every time? Not impossible...
But double testing... double environment, double installs...

> Otherwise, one nasty option (and you're pretty much into nasty options
> if you need to wrap a module with such an unpleasant interface) would be
> to use the (undocumented and unexported) Want::double_return function
> provided you the Want module. This sets up the next return to return
> 'twice', so you could do something like


Should I say that this is exactly the kind of answer I was hoping?
I have to investigate it a bit.
It even seems like an example for making my own, if I could not use
this
one precisely...

Thanks again.
Marc
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      01-21-2010
>>>>> "MG" == Marc Girod <(E-Mail Removed)> writes:

MG> And it is a proprietary binary, to which I talk via stdin/stdout (I
MG> mean that it won't 'select').

huh? do you mean select as in the single arg select which handle
gets print by default? or 4 arg select which multiplexes handles for
i/o? if you mean the 4 arg, you can definitely use that on the subproc's
stdio as that is a common way to manage i/o from a forked process.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Marc Girod
Guest
Posts: n/a
 
      01-21-2010
On Jan 21, 4:37*pm, "Uri Guttman" <(E-Mail Removed)> wrote:

> huh?


Sorry for the confusion.
The problem is probably that I didn't explain what binary I was
talking about.
I don't know how to make this story short, and it goes beyond our
scope.
If you are interested, you can read the docs on CPAN, for the modules
I mentioned, plus ClearCase::Argv which they all use.
But I doubt it is worth your interest unless you may try them, and
this depends on your having access to a ClearCase installation...

Marc
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-21-2010
>>>>> "MG" == Marc Girod <(E-Mail Removed)> writes:

MG> On Jan 21, 4:37*pm, "Uri Guttman" <(E-Mail Removed)> wrote:
>> huh?


MG> Sorry for the confusion.
MG> The problem is probably that I didn't explain what binary I was
MG> talking about.

it is irrelevant about which binary. the issue is how do you manage its
i/o via its stdio. that is the same problem for any binary subprocess
you want to run with its stdio. now you never answered the question
about which select function you meant.

MG> I don't know how to make this story short, and it goes beyond our
MG> scope. If you are interested, you can read the docs on CPAN, for
MG> the modules I mentioned, plus ClearCase::Argv which they all use.
MG> But I doubt it is worth your interest unless you may try them, and
MG> this depends on your having access to a ClearCase installation...

no chance in hell of my having clearcase.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Marc Girod
Guest
Posts: n/a
 
      01-21-2010
On Jan 21, 6:41*pm, "Uri Guttman" <(E-Mail Removed)> wrote:

> it is irrelevant about which binary. the issue is how do you manage its
> i/o via its stdio. that is the same problem for any binary subprocess
> you want to run with its stdio. now you never answered the question
> about which select function you meant.


The C function that the cleartool binary does not use.

I was not saying my code doing select in any way. I meant its *not*
doing select.
It may be me who do not understand...
If I fork part of my script, there will be two instances sharing the
same background process.
I cannot see this work.

Does it make better sense now?

Thanks,
Marc
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-21-2010
>>>>> "MG" == Marc Girod <(E-Mail Removed)> writes:

MG> On Jan 21, 6:41*pm, "Uri Guttman" <(E-Mail Removed)> wrote:
>> it is irrelevant about which binary. the issue is how do you manage its
>> i/o via its stdio. that is the same problem for any binary subprocess
>> you want to run with its stdio. now you never answered the question
>> about which select function you meant.


MG> The C function that the cleartool binary does not use.

MG> I was not saying my code doing select in any way. I meant its *not*
MG> doing select.
MG> It may be me who do not understand...
MG> If I fork part of my script, there will be two instances sharing the
MG> same background process.
MG> I cannot see this work.

MG> Does it make better sense now?

not at all. when you fork, why not pass some flag to tell one of the
procs not to deal with the background process? in the other process,
close off the handles to that background process.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Marc Girod
Guest
Posts: n/a
 
      01-21-2010
On Jan 21, 7:33 pm, "Uri Guttman" <(E-Mail Removed)> wrote:

> not at all. when you fork, why not pass some flag to tell one of the
> procs not to deal with the background process? in the other process,
> close off the handles to that background process.


Not to deal with the background process ?
But what should it do then ?
The whole purpose is to interface it !

It could compute pi decimals, or have dinner.
Once it has a fork...

Marc
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-22-2010
>>>>> "MG" == Marc Girod <(E-Mail Removed)> writes:

MG> On Jan 21, 7:33 pm, "Uri Guttman" <(E-Mail Removed)> wrote:
>> not at all. when you fork, why not pass some flag to tell one of the
>> procs not to deal with the background process? in the other process,
>> close off the handles to that background process.


MG> Not to deal with the background process ?
MG> But what should it do then ?
MG> The whole purpose is to interface it !

MG> It could compute pi decimals, or have dinner.
MG> Once it has a fork...

i am lost as to the big picture now. i either need to read all the older
emails again or you need to explain your goals (and not your
design). you seem to want to run some binary process and manage its
i/o. why does this need to be in the background? what about a simple
fork of it and manage its i/o in an event loop in the parent? this is
fairly easy and there are modules that do all the hard lifting. if this
design isn't good enough explain why you need a more complex
architecture.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Marc Girod
Guest
Posts: n/a
 
      01-22-2010
On Jan 22, 12:46*am, "Uri Guttman" <(E-Mail Removed)> wrote:

> i am lost as to the big picture now.


I am not surprised, and I plead guilty.
But I am not writing something from scratch, and I am not going to
redesign anything too drasticly: I play as if there would be users,
and unpublished packages built upon this framework, which has been
public for many years.

So, I did describe my goals, and you did help me.
I appreciate that it is frustrating, after providing useful answers,
and already investing some effort, to be replied RTFM, or "sorry, I
won't disclose more".
It is just that I don't know where to cut: whereever I do, there will
be a next scope. For quite a long time.
Thanks.
Marc
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Any exit status without explicitely using return /exit Keith Thompson C Programming 10 03-03-2010 12:41 AM
Re: Any exit status without explicitely using return /exit jacob navia C Programming 3 02-24-2010 02:39 PM
Exit code of a batch (using exit /B) Joe Smith Java 4 11-08-2006 12:25 PM
Code to Exit Web App and Exit Internet Explorer =?Utf-8?B?U2FuZHk=?= ASP .Net 7 08-05-2005 01:55 AM
What's the difference of return 0; exit(0);exit(1) QQ C Programming 5 05-10-2005 10:11 PM



Advertisments