Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-18 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found