I've been making a lot of progress in the XML Resume modules I first posted about here, but I've run into a problem with my default XSL stylesheets. Each resume format (Text, HTML, etc), has a default stylesheet I've been using and would like to distribute with the module. I had the idea that rather than using an external file for each of them, I'd stuck them in the __DATA__ section of the module, and pull them in using the <DATA> filehandle. This gives me an output subroutine similar to the following in each of the Resume::Text, Resume::HTML, etc, modules:

sub output { my $self = shift; my ($dom, $xslfile, $stylesheet); if ($self->{'stylesheet'}) { $xslfile = $self->{'basedir'} . $self->{'stylesheet'}; $stylesheet = $self->{'xslt'}->parse_stylesheet_file($xslfile) +; } else { local $/ = undef; my $doc = $self->{'parser'}->parse_string(<DATA>); $stylesheet = $self->{'xslt'}->parse_stylesheet($doc); } $dom = $stylesheet->transform($self->{'dom'}); return $dom->toString(); }

Because each of the modules needs to apply an XSL stylesheet to the XML document containing the resume, I figured I should abstract that part of the output sub into a apply_stylesheet sub in the parent Resume object like so:

sub apply_stylesheet { my $self = shift; my ($dom, $xslfile, $stylesheet); if ($self->{'stylesheet'}) { $xslfile = $self->{'basedir'} . $self->{'stylesheet'}; $stylesheet = $self->{'xslt'}->parse_stylesheet_file($xslfile) +; } else { local $/ = undef; my $doc = $self->{'parser'}->parse_string(<DATA>); $stylesheet = $self->{'xslt'}->parse_stylesheet($doc); } $dom = $stylesheet->transform($self->{'dom'}); return $dom; }

However, as would be obvious to people with more OO experience than I have, when the output sub in a Resume::Text object calls apply_stylesheet (which is defined in the parent Resume package, rather in the child Resume::Text package), the the sub tries to read the data in the __DATA__ section of Resume.pm, not the one in Resume/Text.pm.

If this is a totally wrong-headed way of approaching this issue, please let me know. ;) If not, I'm sure there's a relatively simple solution that I haven't managed to get into my head yet. I'm still fairly new to OO in Perl, and I don't quite grok all it's subtleties yet.

Thanks for any help you can give me,
-rattus
__________
He seemed like such a nice guy to his neighbors / Kept to himself and never bothered them with favors
- Jefferson Airplane, "Assassin"


In reply to OO and <DATA> by rattusillegitimus

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.