Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I don't know whether I had a brand new idea or whether this has already been done.

I have the requirement to generate several report mails. For this I collect some data from some input files and generate mails to certain persons based on this data. The content of this mail is generated by Template::Toolkit2 data.

So what I required is some configuration information for:

  1. What are the input files
  2. What are the template files
  3. Which mail addresses do I have (needed to match names to mail addresses)

My first intention was to use one of the Config::XXX modules. But when I came to the mail templates, I remembered something about T::T2: First level variables are copied and can't be changed, but the structures they point to can be changed. So my T::T2 mail templates look something like this:

[%- Mail.from= 'my.sender@ddress'; Mail.subject= 'This is your requested report'; Mail.cc= [ 'someone.in@cc', 'someoneelse@cc', ]; %] here the body comes

So when invoking the $tt->process, I supply in my variables the "Mail" variable, pointing to an empty hash, and I will receive all the values set in the template:

my $vars= { Mail => {}, # additionally my other variables }; my $output= ''; $tt->process( $template, $vars, \$output) or die $tt->error(); # Here I now have: # $vars->{'Mail'}->{'subject'} etc.

Now I use this approach additionally for my configuration file:

[%- # (String) Name of the main report file Files.defects= 'defect.htm'; # (Hash) additional data files and what to do with asignee # Structure <Name of the data file> => { 'recipient' => ('to'|'no brea +ch to'|'cc') } Files.datafiles ={ 'File1.csv' => { recipient => 'to' }, 'another.csv' => { recipient => 'no breach to'}, 'More.csv' => { recipient => 'cc' }, }; # (Array) List of all mailtemplate file names Files.templates=[ 'report1.tt', 'report2.tt', ]; # (Hash) List of all known e-mail adresses # Structure: <Name as in datafile> => <e-mail @dress> Users.list={ 'Horst Porst' => 'Horst.Porst@my.do.main', 'Frank Schrank' => 'Frank.Schrank@my.do.main', 'Hans Dampf' => 'Hans.Dampf@my.do.main', 'Ijon Tichy' => 'Ijon.Tichy@my.do.main', }; %]

The only things I do is then to invoke that template:

my $config_file= 'sendreport.conf'; my $config= { Users => {}, Files => {}, }; $tt->process($config_file, $config) or die $tt->error();

After that I have all my data in the %$config hash.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

In reply to Configuration Files and Template::Toolkit2 by Skeeve

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (12)
    As of 2014-07-14 12:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (259 votes), past polls