http://www.perlmonks.org?node_id=480411


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...

Replies are listed 'Best First'.
Re^2: problematic OO
by stonecolddevin (Parson) 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.