Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hm, I'm not sure; not being too Twitter-savvy¹ I have a very vague understanding what a "list" and a "subscriber" is in this context. However, it looks like you updated your modules with hardcoded constants whenever you change some list. You could do something like this to read them from various sources like text files or SQLite:
package Twitter::Data; use Modern::Perl; sub new { my $class = shift; return bless {}, $class; } sub accounts { croak("Please override accounts()"); } sub get_account_data { croak("Please override get_account_data()"); } sub all_account_data { my $self = shift; my %accounts; foreach my $acct ($self->accounts) { $accounts{$acct} = $self->get_account_data($acct); } } package Twitter::Data::Text; use Modern::Perl; use Carp; use YAML; use base 'Twitter::Data'; sub new { my $class = shift; my %args = @_; defined $args{db} or croak("`db' arg missing"); -d $args{db} or croak("`db' arg is not a directory"); my $self = $class->SUPER::new(%args); $self->{db} = $args{db}; return $self; } # Get a list of all accounts sub accounts { my $self = shift; return glob("$self->{db}/*"); } sub get_account_data { my ($self, $acct) = @_; return YAML::LoadFile("$self->{db}/$acct/accontdata.yml"); } package Twitter::Data::SQLite; use Modern::Perl; use Carp; use DBIx::Simple; use parent 'Twitter::Data'; sub new { my $class = shift; my %args = @_; defined $args{db} or croak("`db' arg missing"); my $self = $class->SUPER::new(%args); $self->{db} = DBIx::Simple->new("dbi:SQLite:dbname=$args{db}",""," +") or croak("can't open db"); return $self; } # Get a list of all accounts sub accounts { my $self = shift; $self->{sql_acctnames}->execute; return $self->{db}->select('SELECT name FROM accounts')->flat; } sub get_account_data { my ($self, $acct) = @_; return $self->{db}->select('SELECT * FROM accounts WHERE name=?')- +>hash; }
A method like get_account_data would be shared by any underlying implementation so it would work no matter how the account data stuff is actually stored even though you call it on the object that is of a derived class.

¹ I follow a handful of news aggregators and never twit, or whatever the verb is for what you to on Twitter.

In reply to Re^7: RFC on how I'm doing when it comes to writing objects? by mbethke
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":



  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2017-12-11 00:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (285 votes). Check out past polls.

      Notices?