Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Singleton and unblessed refereces.

by tobias_hofer (Friar)
on Jul 10, 2013 at 07:34 UTC ( #1043418=note: print w/ replies, xml ) Need Help??


in reply to Re: Singleton and unblessed refereces.
in thread Singleton and unblessed refereces.

Hi,

Sorry for my late replay.
I still have not found the root-cause.
I made an example where i replaced the OLE-interfaced debugger by the OLE-interface of the excel application (because I do not suppose someone has a PLS UDE debugger at home) and it is working fine - its completely bizzare to me. However, if i am doing the same with the debugger OLE Application i get the $debugger variable as undefined.

Please have a look

Here my example code:

TestMe.pl

########################################## #Perl file which shall use the "debugger" ########################################## use strict; use warnings; use diagnostics; use myDebugger; my $_db = GetInstance(); print "Does not work\n" if (not defined $_db); print "Is working fine\n";
myDebugger.pm
########################################## #Perl file myDebugger.pm ########################################## package myDebugger; use strict; use warnings; use Win32::OLE; use Win32::OLE::Const "Microsoft Excel"; use Win32::OLE qw(in with); use Win32::OLE::Variant; use vars qw($VERSION $HEADER @ISA @EXPORT); use Exporter; $VERSION = q$Revision: 1.1 $; $HEADER = q$Header: Some CMS data... $; @ISA = qw(Exporter); @EXPORT = qw( GetInstance ); # export subs my $debugger = undef; sub GetInstance { if ( defined $debugger ) { return $debugger; } else { DebuggerInit(); defined $debugger ? return $debugger : print " Init error!"; return 0; } } sub DebuggerInit { # Instead of an Debugger, I use here the Excel-Application. # Both excel and the debugger application are interfaced by OLE # Thus I think its a good replacement as an example. # Also the way how the OLE Application is the same # as the originally used UDE PLS Debugger. $debugger = Win32::OLE->GetActiveObject('Excel.Application'); unless ($debugger) { $debugger = new Win32::OLE( 'Excel.Application', \&main::QuitA +pp ); } } sub main::QuitApp { exit(); } 1;


Comment on Re^2: Singleton and unblessed refereces.
Select or Download Code
Re^3: Singleton and unblessed refereces.
by Corion (Pope) on Jul 10, 2013 at 07:50 UTC

    I would add far more checks/tracing to DebuggerInit. Maybe ->GetActiveObject() does differ in behaviour for the debugger, or creating the new object fails if the debugger application is not already running. Output the functions called and the results in DebuggerInit.

    Your choice of setting up a call to exit() in the object destructor:

    $debugger = new Win32::OLE( 'Excel.Application', \&main::QuitApp );

    ... strikes me as weird. I use the call to properly tear down the OLE object, and not to exit the Perl script in a very hard way. Maybe the debugger application does not like that method of improper cleanup. As a first start, I would not try to quit the OLE application at all upon script exit. This will likely leave you with headless processes accumulating, at least it does with Excel. After trying that, I would look at finding the proper way to quit the debugger application. Maybe you need to do nothing, or you need to do the same thing that the Win32::OLE documentation suggests, except in the appropriate way for your debugger:

    $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) # calls $ex->Quit() when the Perl program ends or $ex goes out of +scope

    As a personal style option, I would not cache the $debugger in a file-global lexical variable. In most cases, using a proper global variable in the packages is better for me, because it allows me to explicitly undef such variables for debugging purposes.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-12-25 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls