Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

To expand on what mbethke said:

Think of each of your accounts as an entity that is self (pun intended) contained - It has information about that account stored in it and has methods that know what to do with that information.

Each of these entities could be an object, the template for which is defined by the class that you write like so:

package My::Twitter::Account; use strict ; use warnings ; .... sub new { my $class = shift; my %parameter_hash; my $count = @_; %parameter_hash = @_; croak( "MISSING FILE : \n " . $useage_howto ) unless( $ +parameter_hash{ FILE } ) ; croak( "MISSING HEADINGS: \n " . $useage_howto ) unless( $ +parameter_hash{ HEADINGS } ) ; croak( "MISSING NAME : \n " . $useage_howto ) unless( $ +parameter_hash{ NAME } ) ; $parameter_hash{ DEBUG } = 0 unless( $parameter_hash{ DEBUG } ); my $self = { FILE => $parameter_hash{ FILE } , HERADINGS => $parameter_hash{ HEADINGS } , NAME => $parameter_hash{ NAME } , SOME_USEFUL_INFO_MAYBE => $other_useful_info , DEBUG => $parameter_hash{ DEBUG } , } bless( $self, $class ); dump( $self ) if( $self->{DEBUG} == 1 ); return $self; } ... Other Methods that deal with a SINGLE twitter account here.

Now that we have something to deal with a single account we can combine these either into a second package or decide to use them in a non-OO way. Lets do the First:

package My::Twitter::AllAccounts; use strict ; use warnings ; ... blah blah blah sub new { my $class = shift; my %parameter_hash; $parameter_hash{ DEBUG } = 0 unless( $parameter_hash{ DEBUG } ); my @twitter_accounts ; my $self = { TWITTER_ACCOUNTS => \@twitter_accounts , DEBUG => $parameter_hash{ DEBUG } , } bless( $self, $class ); dump( $self ) if( $self->{DEBUG} == 1 ); return $self; } sub add_twitter_account { my $self = shift ; my $name = shift ; my ( $file, $headings ) = _function_that_gets_files_and_headi +ngs(); # This can also be inside the Twitter::Account class. my $twitter_account = new My::Twitter::Account( NAME => $name , FILE => $file , HEADINGS => $headings , ); push( @{ $self->{ TWITTER_ACCOUNTS } }, $twitter_account ) ; return 1; }

Now we have a way to store a single twitter account and a way to store the collection we can do things like:

my $twitter_data = new My::Twitter::AllAccounts() ; my @accounts = qw( Lady_Aleena LadyAleena_ABC LadyAleena_CBS LadyAleena_FOX LadyAleena_NBC LadyAleena_SyFy LadyAleena_TNT LadyAleena_USA LadyAleena_TV LadyAleena_eros LadyAleena_home LadyAleena_test ); foreach my $account ( @accounts ) { $twitter_data->add_twitter_account( $account ); }

Of course the really fun part begins now:

# Am assuming you move your functions into the correct classes and wri +te some ... But the below is just for illustration. $twitter_data->reload_account_data( $account_name ); $twitter_data->get_sum_of_all_accounts(); $twitter_data->remove_twitter_account( $account ); $twitter_data->temporarily_ignore_accounts( [ account1, account2 ] ); $twitter_data->get_sum_of_all_accounts(); $twitter_data->stop_ignoring();

In reply to Re^3: RFC on how I'm doing when it comes to writing objects? by tmharish
in thread RFC on how I'm doing when it comes to writing objects? by Lady_Aleena

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-19 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found