in reply to Did I use Net::Twitter::lite correctly for moving lists between accounts?
The following is not an answer to your question, but may help you with testing your code. I've mocked Net::Twitter::Lite using Test::MockObject to avoid needing to use Twitter in testing the code at all. I've also removed all the stuff I didn't understand that prevented the code running and generating what looks like it may be useful output and I've printed to the console rather than generate output files. With all that in mind, consider:
use warnings; use strict; use Test::MockObject; my $mock; BEGIN { $mock = Test::MockObject->new (); $mock->fake_module ('Net::Twitter::Lite'); $mock->fake_new ('Net::Twitter::Lite'); $mock->mock (get_lists => \&mock_get_lists); $mock->mock (list_members => \&mock_list_members); $mock->mock (list_subscribers => \&mock_list_subscribers); } require Net::Twitter::Lite; my $directory = 'personal/Twitter'; my $twit_id = "Lady_Aleena"; my $nt = Net::Twitter::Lite->new ( consumer_key => 'in the code', consumer_secret => 'in the code', access_token => 'in the code', access_token_secret => 'in the code', ); # Not all data I want is on Twitter, some of these lists are not creat +ed, # but I want to create them in the third script. my %twitter_lists = ( 'Andromeda' => {'network' => 'unknown',}, 'Babylon 5' => {'network' => 'unknown',}, 'Body of Proof' => {'network' => 'ABC',}, 'Bones' => {'network' => 'FOX',}, 'Buffy and Angel' => {'network' => 'unknown',}, 'Burn Notice' => {'network' => 'USA',}, 'Castle' => {'network' => 'ABC',}, 'Chuck' => {'network' => 'NBC',}, 'Covert Affairs' => {'network' => 'USA',}, 'Doctor Who' => {'network' => 'BBC',}, 'ER' => {'network' => 'NBC',}, 'Eureka Warehouse13 Alphas' => {'network' => 'Syfy',}, 'Firefly' => {'network' => 'unknown',}, 'Haven' => {'network' => 'Syfy',}, 'Law & Order' => {'network' => 'NBC',}, 'Leverage' => {'network' => 'TNT',}, 'Necessary Roughness' => {'network' => 'USA',}, 'No Ordinary Family' => {'network' => 'ABC'}, 'Rizzoli & Isles' => {'network' => 'TNT',}, 'Sanctuary' => {'network' => 'Syfy',}, 'seaQuest' => {'network' => 'NBC',}, 'Stargate' => {'network' => 'Syfy',}, 'Star Trek' => {'network' => 'unknown',}, 'Studio 60' => {'network' => 'NBC',}, 'White Collar' => {'network' => 'USA',}, 'The X-Files & Millennium' => {'network' => 'FOX',}, ); # my @raw_lists; for (my $cursor = -1; $cursor;) { my $r = $nt->get_lists ({user => $twit_id, cursor => $cursor}); push @raw_lists, @{$r->{lists}}; $cursor = $r->{next_cursor}; } my @lists; for my $list (@raw_lists) { my $name = $list->{'name'}; $twitter_lists{$name}{'name'} = $name; $twitter_lists{$name}{'slug'} = $list->{'slug'}; $twitter_lists{$name}{'id'} = $list->{'id'}; $twitter_lists{$name}{'mode'} = $list->{'mode'}; $twitter_lists{$name}{'description'} = $list->{'description'}; push @lists, $list->{'slug'}; } my %raw_lists_follows; for my $list (@lists) { for (my $cursor = -1; $cursor;) { my $r = $nt->list_members ($twit_id, $list, {cursor => $cursor +}); push @{$raw_lists_follows{$list}{following}}, @{$r->{users}}; $cursor = $r->{next_cursor}; } for (my $cursor = -1; $cursor;) { my $r = $nt->list_subscribers ($twit_id, $list, {cursor => $cu +rsor}); push @{$raw_lists_follows{$list}{followers}}, @{$r->{users}}; $cursor = $r->{next_cursor}; } } for my $raw_list (keys %raw_lists_follows) { my $list = get_list_name ($raw_list); for my $following (@{$raw_lists_follows{$raw_list}{following}}) { my $name = $following->{'name'}; $twitter_lists{$list}{following}{$name}{'name'} = $name; $twitter_lists{$list}{following}{$name}{'screen_name'} = $following->{'screen_name'}; $twitter_lists{$list}{following}{$name}{'id'} = $following->{' +id'}; } for my $followers (@{$raw_lists_follows{$raw_list}{followers}}) { my $name = $followers->{'name'}; $twitter_lists{$list}{followers}{$name}{'name'} = $name; $twitter_lists{$list}{followers}{$name}{'screen_name'} = $followers->{'screen_name'}; $twitter_lists{$list}{followers}{$name}{'id'} = $followers->{' +id'}; } } my @twitter_list_file_lines; for my $twitter_list (sort keys %twitter_lists) { my $tl = $twitter_lists{$twitter_list}; my $listName = $tl->{list_name}; next if ! defined $tl->{slug}; push @twitter_list_file_lines, @{$tl}{qw(name slug id description +network)}; for my $follow ('following', 'followers') { my @person_list_lines = (); for my $person (sort keys %{$tl->{$follow}}) { my $follow_name = $tl->{$follow}{$person}{name}; my $follow_screen_name = $tl->{$follow}{$person}{screen_na +me}; my $follow_id = $tl->{$follow}{$person}{id}; push @person_list_lines, qq($follow_name|$follow_screen_name|$follow_id); } print "PLF: ", join ("\n ", @person_list_lines), "\n"; } } print "\nTLF: ", join "\n ", @twitter_list_file_lines, ''; sub get_list_name { my ($slug) = @_; for my $twitter_list (keys %twitter_lists) { next if !defined $twitter_lists{$twitter_list}{slug}; if ($twitter_lists{$twitter_list}{slug} eq $slug) { return $twitter_list; } } } sub mock_get_lists { my ($self, $params) = @_; my %listsByUser = ( Lady_Aleena => [ { name => 'Andromeda', slug => 1, id => 1, description => 'Broom cupboard', network => 'ethernet' }, ], ); my $lists = $listsByUser{$params->{user}}; return $params->{cursor} ? {lists => $lists} : $lists; } sub mock_list_members { my ($self, $twit_id, $list, $params) = @_; my %membersById = ( Lady_Aleena => [ [ {name => 'Joe', screen_name => 'Stretch', id => 4}, {name => 'Bill', screen_name => 'Bill', id => 5}, {name => 'Sarah', screen_name => 'Sam', id => 6}, ], ], ); my $members = $membersById{$twit_id}[$list - 1]; return $params->{cursor} ? {users => $members} : $members; } sub mock_list_subscribers { my ($self, $twit_id, $list, $params) = @_; my %subscribersById = ( Lady_Aleena => [ [ {name => 'Sandy', screen_name => 'Grit', id +=> 1}, {name => 'Carla', screen_name => 'Carla', id +=> 2}, {name => 'Fred', screen_name => 'Fish and Chips', id +=> 3}, ], ], ); my $subscribers = $subscribersById{$twit_id}[$list - 1]; return $params->{cursor} ? {users => $subscribers} : $subscribers; }
Prints:
PLF: Bill|Bill|5 Joe|Stretch|4 Sarah|Sam|6 PLF: Carla|Carla|2 Fred|Fish and Chips|3 Sandy|Grit|1 TLF: Andromeda 1 1 Broom cupboard unknown
|
|---|