Note that there are some explanatory texts on larger screens.

plurals
  1. POCan Perl handle this OOP concept - Explained in Animal Terms
    text
    copied!<p>Sorry for being very vague but I do not know the name of the concept. I will try to explain. I'll try to put it in terms of animals to make it easy.</p> <p>I have a generic superclass. This superclass contains functions that all animals have to do. For example I do not want to redefine "take_breath" sub in every animal subclass, so I define it once inside the Animals superclass and all of the animals (Animals::Cat, Animals::Dog, and Animals::Llama) can simply access $self->take_breath(). The animals also go through many of the same initialization routines so as opposed to redefining them every time I simply call $class->SUPER::new(@_) as well as do things specific to that animal.</p> <p>With this being said every time an animal is initialized it goes through it's superclasses' initialization routines. There are hundreds of animals and these are run hundreds of times. It's not too big of a problem.</p> <p>These animals are smart however and know how to use the LWP::UserAgent web browser. In order to access the internet they must log into a web page and set their session cookies. They all share the same login and would like to share the same browser. In my current implementation the login routines are part of the superclass's new method. This means when an animal is initialized this runs and the animal logs in. As I said I have hundreds of animals and do not want to fire off hundreds of POST requests. I would like to somehow fire off the login routine once and make it part of the super class. Each animal can then access the "shared" web browser by doing $self->{'ua'}.</p> <p>I hope this explains it, I am not sure what this OOP term is called.</p> <p><strong>TLDR for those who don't like Animals</strong></p> <p>I have a login routine in the superclass that creates an LWP::UserAgent, logs in, and sets session cookies. The subclasses can all share one login. I do not want to have to fire off hundreds of POST requests to log in for each subclass. I would like to somehow log in once and share the prepared $ua object wil all subclasses.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload