rattusillegitimus has asked for the wisdom of the Perl Monks concerning the following question:
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"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: OO and <DATA>
by Zaxo (Archbishop) on Aug 25, 2002 at 05:56 UTC | |
by rattusillegitimus (Friar) on Aug 25, 2002 at 18:29 UTC | |
Re: OO and <DATA>
by dws (Chancellor) on Aug 25, 2002 at 07:04 UTC | |
by trs80 (Priest) on Aug 25, 2002 at 16:05 UTC | |
by BUU (Prior) on Aug 25, 2002 at 17:28 UTC | |
by jeffa (Bishop) on Aug 25, 2002 at 18:40 UTC |