Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
P is for Practical
 
PerlMonks  

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 = 'pop.dnvr.qwest.net'; sub new { my ( $class, $to ) = @_; my $self = { Smtp => $server, From => 'Postmaster', To => $to ? $to : 'devin.austin@gmail.com', }; # 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
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...
    meh.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-04-21 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (495 votes), past polls