Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How can I keep object arguments private

by ikegami (Patriarch)
on May 24, 2010 at 06:21 UTC ( [id://841327]=note: print w/replies, xml ) Need Help??


in reply to How can I keep object arguments private

and expect a hashref of the return value.

Then what are you doing returning an object ($self)? I'm not clear on what your object is suppose to do. Tell us about your object and what the referenced hash should contain and we'll help you further.

After looking some more, I think my approach would be something like

{ package Meteoalarm; sub new { my ($class, %args) = @_; my $self = bless({}, $class); $self->{ua} = _make_ua(); return $self; } sub _make_ua { return LWP::UserAgent->new( ... ); } sub get_warnings { my ($self) = @_; my $ua = $self->{ua}; ... my %by_country; for (...) { ... $by_country{$country} = \%warning; } return \%by_country; } }
or
{ package Meteoalarm; sub new { my ($class, %args) = @_; my $self = bless({}, $class); $self->{ua} = _make_ua(); return $self; } sub _make_ua { return LWP::UserAgent->new( ... ); } sub fetch { my ($self) = @_; my $ua = $self->{ua}; ... my @countries; for (...) { ... push @countries, Meteoalarm::Country->new( name => $country, warnings => \%warnings, ); } return \@countries; } } { package Meteoalarm::Country; sub new { my ($class, %args) = @_; my $self = bless({}, $class); $self->{name } = $args{name }; $self->{warnings} = $args{warnings}; return $self; } sub name { shift->{name } } sub warnings { shift->{warnings} } }
Or maybe something else. It really depends on how you plan on using the objects.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found