nysus has asked for the wisdom of the Perl Monks concerning the following question:
I'm stretching my very underdeveloped OO muscles and looking for a little guidance.
I've got this perl script which creates a EventRepository object:
#!/usr/bin/perl use strict; use warnings; use EventRepository; my $er = EventRepository->new; $er->gets('http://google.com');
The EventRepository ISA subclass of class FFMech. The EventRepository code looks like this:
package EventRepository; use strict; use warnings; use vars qw(@ISA); @ISA = qw (FFMech); sub new { my $self = {}; bless $self, shift; logi('Creating event repository.'); $self->{_mech} = FFMech->new(); return $self; }
And here is a snippet from the FFMech class, which is basically just a wrapper for WWW::Mechanize::Firefox and has some custom functions that I wrote.
package FFMech; use strict; use warnings; use vars qw(@ISA); @ISA = qw (WWW::Mechanize::Firefox); use X11::GUITest qw/SendKeys FindWindowLike ClickWindow SetEventSendDe +lay/; sub new { my ($class, %args) = @_; my $self = {}; bless $self, shift; $self->_init(@_); return $self; } sub _init { my ($self, %args) = @_; $self->{_mech} = WWW::Mechanize::Firefox->new(launch => 'firefox', a +ctivate => 1 ); $self->{_window_id} = FindWindowLike('Mozilla Firefox'); ClickWindow($self->{_window_id}); if ($self->{_mech}->title =~ /Restore Session/i) { $self->{_mech}->click( {selector => '#errorCancel' } ); } } sub gets { my $self = shift; my ($url, $sec, $syn) = set_args(@_); $self->{_mech}{_mech}->get($url, sychronize => $syn); sleep($sec); }
Though the code works, I can't be doing things properly. In particular, the gets() method in the FFMech class has this line :
$self->{_mech}{_mech}->get($url, sychronize => $syn);
Clearly this is not correct because gets() should not have to know how many levels deep or what methods to call on the object to get to the get() method. I'm missing something fundamental here. Can someone please point me in the right direction? How do I properly call WWW::Mechanize::Fixefox->get() method using the EventRepository object?
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
$nysus = $PM . $MCF;
Click here if you love Perl Monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Proper way to call subclass methods?
by choroba (Cardinal) on Mar 08, 2016 at 00:32 UTC | |
by nysus (Parson) on Mar 08, 2016 at 16:57 UTC | |
|
Re: Proper way to call subclass methods?
by Tanktalus (Canon) on Mar 08, 2016 at 16:07 UTC | |
by nysus (Parson) on Mar 08, 2016 at 17:12 UTC | |
by Your Mother (Archbishop) on Mar 08, 2016 at 17:32 UTC | |
by nysus (Parson) on Mar 08, 2016 at 19:16 UTC | |
by Your Mother (Archbishop) on Mar 08, 2016 at 19:23 UTC | |
by Anonymous Monk on Mar 09, 2016 at 00:40 UTC | |
| |
|
Re: Proper way to call subclass methods?
by nysus (Parson) on Mar 11, 2016 at 16:45 UTC |