Changeset 4bd9327


Ignore:
Timestamp:
Aug 4, 2009, 2:38:06 AM (15 years ago)
Author:
Kevin Riggle <kevinr@free-dissociation.com>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
8462b38
Parents:
513da71
Message:
Refactor commands which do something on the default account handle
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/BarnOwl/Module/Twitter.pm

    r513da71 r4bd9327  
    187187}
    188188
    189 sub twitter_direct {
    190     my $account = shift;
    191 
    192     my $sent = 0;
     189# do_for_default_account( SUB( HANDLE, ARGS...), ACCOUNT, ARGS... )
     190sub do_for_default_account {
     191    my $lambda = shift;
     192    die ("do_for_default_account has nothing to do") unless defined $lambda && ref($lambda) eq 'CODE';
     193    my $account = shift;
     194
    193195    if (defined $account) {
    194196        my $handle = find_account($account);
    195         $handle->twitter_direct(@_);
     197        $lambda->($handle, @_);
    196198    } elsif (defined $default_handle) {
    197         $default_handle->twitter_direct(@_);
     199        $lambda->($default_handle, @_);
    198200    }
    199201    else {
    200         $twitter_handles[0]->twitter_direct(@_);
    201     }
     202        $lambda->($twitter_handles[0], @_);
     203    }
     204}
     205
     206sub twitter_direct {
     207    my $account = shift;
     208    do_for_default_account( sub { my $handle = shift; $handle->twitter_direct(@_); }, $account, @_);
    202209}
    203210
    204211sub twitter_atreply {
    205212    my $account = shift;
    206 
    207     my $sent = 0;
    208     if (defined $account) {
    209         my $handle = find_account($account);
    210         $handle->twitter_atreply(@_);
    211     }
    212     elsif (defined $default_handle) {
    213         $default_handle->twitter_atreply(@_);
    214     }
    215     else {
    216         $twitter_handles[0]->twitter_atreply(@_);
    217     }
     213    do_for_default_account( sub { my $handle = shift; $handle->twitter_atreply(@_); }, $account, @_);
    218214}
    219215
    220216sub twitter_follow {
    221217    my $account = shift;
    222 
    223     if (defined $account) {
    224         my $handle = find_account($account);
    225         $handle->twitter_follow(@_);
    226     } elsif (defined $default_handle) {
    227         $default_handle->twitter_follow(@_);
    228     }
    229     else {
    230         $twitter_handles[0]->twitter_follow(@_);
    231     }
     218    do_for_default_account( sub { my $handle = shift; $handle->twitter_follow(@_); }, $account, @_);
    232219}
    233220
    234221sub twitter_unfollow {
    235222    my $account = shift;
    236 
    237     if (defined $account) {
    238         my $handle = find_account($account);
    239         $handle->twitter_unfollow(@_);
    240     } elsif (defined $default_handle) {
    241         $default_handle->twitter_unfollow(@_);
    242     }
    243     else {
    244         $twitter_handles[0]->twitter_unfollow(@_);
    245     }
     223    do_for_default_account( sub { my $handle = shift; $handle->twitter_unfollow(@_); }, $account, @_);
    246224}
    247225
Note: See TracChangeset for help on using the changeset viewer.