$c->{eprint_status_change} = sub { my( $eprint, $old_status, $new_status ) = @_; if( $new_status eq "archive" ) { my $twitter_username="OtagoSoBEprints"; my $twitter_password="mmpcfjXIm1jY0cU"; # NJS 2009-12-07: Rewrote completely to check for existence # of curl, wget, etc. Also now truncates the title if the # tweet would otherwise be longer than 140 characters. my $isgdCmd = ''; my $twitterCmd = ''; my $shorturl = ''; my $title = $eprint->get_value( "title" ); $title =~ s/'/\\'/g; if ( length( $title ) > 118 ) { $title = substr( $title, 0, 118 ) . 'É'; } SWITCH: foreach ( 'curl', 'wget' ) # add others here and below { # Try to call the command, if it's not in the path then $? # will be -1 and $! will be 'No such file or directory'. # If nothing works, just fail silently. system( $_ ); if ( $? != -1 ) { if ( /curl/ ) { $isgdCmd = "curl --silent 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; $twitterCmd = "curl --silent --basic --user $twitter_username:$twitter_password --data status='$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } if ( /wget/ ) { $isgdCmd = "wget --quiet --output-document=- 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; $twitterCmd = "wget --quiet --http-user=$twitter_username --http-password=$twitter_password --post-data='status=$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } } } } };