I have a module that represents a configuration file object, say ConfigFile.pm which reads a
Configfile.txt file. The overall application is tournament scoring and the ConfigFile
contains things like tournament names, various "handicap" values, etc. There are a lot of
ways to go wrong when writing the ConfigFile so I have a test/validator program. The output
of this test program is not a simple pass/fail module test, but is rather a development tool to inform the
user about potential inconsistencies with the purpose of ensuring that the overall program is
going to do what the user intends (which may not be what the ConfigFile instructs the program to do!).
Rather than having a separate validator program, I'd like to have the module behave differently
when it is executed perl ConfigFile.pm rather than when it is "used", ie: use ConfigFile.pm.
I remember that there is an easy way for the module to know this difference but I have been unable
to find this "trick". So my question is how to I do this?
Update:Thanks to Choroba, my code will become: validate() unless caller;
PS: Sorry for long explanation, but I wanted to head off any XY discussion. Yes, this is what I want. validate() is already a method for the object, so I can get rid of an extra .pl file.
Update 2: I thank the Monks for a robust discussion. I've learned at least a couple of things and I thank you all for that.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.