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

Re: Splitting program into modules

by eyepopslikeamosquito (Archbishop)
on Nov 11, 2018 at 05:11 UTC ( [id://1225560]=note: print w/replies, xml ) Need Help??


in reply to Splitting program into modules

my main goal is to document code, understand it's flow and based on that create another functionality

I've kept a list of PM nodes over the years related to this topic.

Legacy Code

Adding Tests to Legacy Code

Replies are listed 'Best First'.
Re^2: Splitting program into modules
by lis128 (Acolyte) on Nov 11, 2018 at 17:16 UTC

    I must say that feedback overgrown my expectations.
    Thank you all for humongous repository of things to read- i really appreciate that
    I just wanted to say that i did not abandoned topic and will try to dig through your advices and links.

    In meantime, i've managed to isolate similiar functionalities without switching namespaces. I just got rid of package statements and usage of Exporter module, but this leads to another problem
    As i wrote earlier i am using my own simple debugging routines (yes i know it can be done better, but i am developing these modules giving them required functionality). Let's code speak for himself

    my $debug = $ENV{'dbg'}; sub debugInfo { my $iWasAt= ( caller(1) )[3] || "main"; my $lineWhereCalled= ( caller(0) )[2] || ( caller(1) )[2]; print STDERR ("\033[1;31m\t$iWasAt\033[0m\@\033[1;32m$lineWhereCal +led:\033[0m \t\t@_\n") if ($debug); }

    Until now everything went fine, i called debugInfo("entry: @_"); and i received package name with corresponding line where call was made, like
    main@139: wchodze w loopa, iteracja:4 Database::sql_connect@144: entry: API::base@13: entry: config

    Now, my simple use'ing packages not being packages makes my $iWasAt always being main, also lines are relative to module file line number.
    So i am looking for another solution, but i feel that with you hackers, nothing's impossible :)
    Going do read thoroughly through your posts, thanks angain

      As I already said you should start by splitting your 14000 lines into multiple files and require or do them, no need to switch packages at the first step.

      (Careful about filescoped private variables)

      Since caller will also tell you the filename, your debug routine can be more explicit then.

      Btw: Using the trace option of the debugger might be another option.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      I'm a big fan of the Log::Log4perl module for logging. For me, the terrific feature of this module is that you can adjust the level of messages you get in your log file -- dial it up to DEBUG to get everything, or back down to WARN for just warnings. In between the two is INFO, containing useful messages about what my scripts are doing.

      If you add log messages to the various modules that you are developing, you'll be able to track in what orders things are happening. It's really illuminating to see this stuff scroll by -- I have status screens that watch the tail end of various log files during production hours so I can stay on top of how my system is behaving.

      Good luck -- let us know how it all turns out.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2024-03-28 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found