$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 $urlCmd = ''; 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 { # NJS 2010-01-12: Changed to use which instead of $? value. # Check that the command exists using which. If it exists # then the output of which will start with '/', otherwise # it won't (it will usually be empty or something like # "no such ..." or "foo: not found") $urlCmd = `which $_`; chomp $urlCmd; if ( $urlCmd =~ m|^/| ) { if ( /curl/ ) { $isgdCmd = "$urlCmd --silent 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; $twitterCmd = "$urlCmd --silent --basic --user $twitter_username:$twitter_password --data status='$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } if ( /wget/ ) { $isgdCmd = "$urlCmd --quiet --output-document=- 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; $twitterCmd = "$urlCmd --quiet --http-user=$twitter_username --http-password=$twitter_password --post-data='status=$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } } } } };