Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^7: RFC on how I'm doing when it comes to writing objects?

by mbethke (Hermit)
on Feb 07, 2013 at 06:44 UTC ( [id://1017574]=note: print w/replies, xml ) Need Help??


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.

Replies are listed 'Best First'.
Re^8: RFC on how I'm doing when it comes to writing objects?
by Lady_Aleena (Priest) on Feb 08, 2013 at 15:20 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1017574]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-18 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found