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.