Making a function callable on an objectby George_Sherston (Vicar)
|on Apr 15, 2002 at 23:14 UTC ( #159363=perlquestion: print w/replies, xml )||Need Help??|
George_Sherston has asked for the wisdom of the Perl Monks concerning the following question:
I have a subroutine to help me work with PDF::Create. It accepts a hashref as argument, which must contain page, font and text, and can contain some other optional parameters. In return it lays out the text in lines of appropriate width and spacing - that is, turns a string of text into a column of text in PDF file.
The usage of the module, and the module itself, are below.
My question is about the way I call the module. As you see, having created a new page object using PDF::Create, I then pass this object to my subroutine, which modifies it and returns it. What I'd like to know how to do is write it so I could call it thus: $page->PDFColumn(....). This seems neater than the three-card monty I have to do at present with objects going back and forth. (Although on mature consideration I think I may wish to pass back the modified $height parameter as well)
One thing I know I'd have to do is alter the start of my subroutine to get the page directly rather than as an element in a hashref. But that's clearly not all there is to it. I know little of OO, less of Perl OO. I read through bless, but this doesn't seem to be what I want. I'd be very grateful if any kind monk cd steer me in the direction of an explanation.
§ George Sherston
Back to Seekers of Perl Wisdom