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


In reply to Proper way to call subclass methods? by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.