Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created April 19, 2010 08:46
Show Gist options
  • Save fujiwara/370854 to your computer and use it in GitHub Desktop.
Save fujiwara/370854 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common;
use Path::Class qw/ file /;
use Try::Tiny;
my $host = "fujiwara-mac";
my $port = 9292;
my $file = shift;
my $content = try { file($file)->slurp };
my $ua = LWP::UserAgent->new( timeout => 0 );
my $res = $ua->request(
POST "http://$host:$port/edit",
Content => $content,
);
if ($res->is_success) {
rename "$file", "${file}~";
my $fh = file($file)->openw or die $!;
print $fh $res->content;
}
else {
die $res->status_line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment