http://www.perlmonks.org?node_id=1017574


in reply to Re^6: RFC on how I'm doing when it comes to writing objects?
in thread RFC on how I'm doing when it comes to writing objects?

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.