|Think about Loose Coupling
OO and <DATA>by rattusillegitimus (Friar)
|on Aug 25, 2002 at 05:46 UTC
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:
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:
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,