Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: problematic OO

by polypompholyx (Chaplain)
on Aug 03, 2005 at 09:17 UTC ( #480411=note: print w/ replies, xml ) Need Help??

in reply to problematic OO

There are a few problems here. Mostly they seem to be to do with your understanding of what $self actually is. $self is generally a hashref, which contains your instance variables, like 'To' and 'Smtp'.

At the moment, your new method blesses an empty hashref containing no data. $self should probably contain the data you currently assign to %mail. Something like...

package PL::Mail; my $server = ''; sub new { my ( $class, $to ) = @_; my $self = { Smtp => $server, From => 'Postmaster', To => $to ? $to : '', }; # hashref containing instance variables return bless $self, $class; }

There are similar problems in your send method. You are also calling the send method incorrectly. You want something like...

my $obj = PL::Mail->new( $recipient ); $obj->send( subject => 'blah', comments => 'ftui' ):

Note that because you are passing these parameters to send as a list, the way you handle send's arguments needs to be something like...

my( $self, %params) = @_; $self->{ subject } = $params{ subject }; ...

Don't be too disheartened: at least you're using  strict :) I think you could do with having a look at perltoot. Also, Mail::Sendmail is so simple, I'm not sure if you really need to be writing a wrapper for it...

Comment on Re: problematic OO
Select or Download Code
Replies are listed 'Best First'.
Re^2: problematic OO
by stonecolddevin (Vicar) on Aug 03, 2005 at 19:43 UTC
    It is very simple....and I had thought of trashing my wrapper until I got it to work...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://480411]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2015-10-04 20:14 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (104 votes), past polls