One thing I see quickly is that your pass your hash of tokens into loadAndParse, but that function does not pass them to any other function, nor does it set the $self->{tokens} attribute. Basically, the rest of your functions have nothing to work on. I don't think this will solve all the problems though.

Update:
Also, in your new function, I believe you have your %tokens call defined incorrectly. It looks like you want $self->{tokens} to be a hash containing the token as the key, and it's replacement as it's value. You would need something like:

sub new { ... $self->{tokens} = \%tokens; ... }
This would define the token attribute of $self to be a hashref containing your mapping of token names to token values. However, rather than relying on %tokens being defined globally, I would recommend that you pass it into either your constructor, or propagate it through your parseData function.

Update II:
You could also do away with the $self->{tokens} part of your module all together. The tokens are only used in one place throughout your module---the parseData function. So you could change the code to:

sub parseData($) { my $self = shift; my ($data, %tokens) = @_; foreach my $match($data =~ /\%(\S+?)\%/g) { if($tokens{$match}) { $data =~ s/%$match%/$tokens{$match}/g; } else { $data =~ s/%$match%//g; } } $debug .= "parseData has been run<br>"; return($data); }
and change the loadAndParse function to:
sub loadAndParse($%) { my $self = shift; my ($filename,%tokens) = @_; $data = loadFile($filename); $body = parseData($data, %tokens); $debug .= "parseData has been run<br>"; return($body); }


In reply to Re: Perl Modules by Belgarion
in thread Perl Modules by eNtropicChild

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.