I've been roped into writing a couple of scripts at work, and I noticed they share a lot of code. I'd like to pull that code out into a package.

They're scripts that report various statistics to DBAs---I won't go into the details---and they're both configurable to output to email, standard output, logfiles, or any combination of the above.

So I wrote a package that simply declares a bunch of our variables.

our $usemail = 0; our $mailto = 'root@localhost'; our $mailfrom = 'admin@localhost'; our $mailserver = 'smtp'; our $usestdout = 1;
Then, the script sets the variables to configure:
$Reporting::usemail = 1;
Okay, this works, but I don't like it. What I'd really like to do is be able to pull in chunks of my code with something like
#!/usr/bin/perl use Reporting qw/EMail Stdout/; $Reporting::EMail::to = "root@server"; @report=("Everything is fine.","Nothing is broken."); &Reporting::Send(@report);
So that the sort of reporting would be clear at a glance from the use line, and not be dependent on some long variables further down. In summary, I want to write a package that works sort of like use strict; I can give the use line a list of "options" and it behaves differently depending on what I gave it... something like the following pseudocode:
package Reporting; my @sendtasks; if (used "EMail") { use EMail shift @sendtasks,\&EMail::Send; }
Is this possible? Is this easy? Is this really obvious how to do? Am I way off base? Most package-writing tutorials have been really unenlightening. Please help, magnanimous monks...

/usr/bin/perl '-nemap$.%$_||redo,2..$.++;print$.--'

In reply to Pragma-like package by dbw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.