| 1 | #!/usr/local/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use LWP::UserAgent; | ||
| 5 | |||
| 6 | my $ua = LWP::UserAgent->new(); | ||
| 7 | |||
| 8 | &main;exit; | ||
| 9 | |||
| 10 | sub get { | ||
| 11 | my $url = shift; | ||
| 12 | my $res = $ua->get($url); | ||
| 13 | $res->is_success or die "cannot get $url"; | ||
| 14 | $res; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub get_xrds_location { | ||
| 18 | my $entry_point = shift; | ||
| 19 | my $res = get($entry_point); | ||
| 20 | my $xrds_location = $res->header('X-XRDS-Location') or die 'x-xrds-location not found'; | ||
| 21 | return $xrds_location; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub main { | ||
| 25 | my $url = shift @ARGV or die "Usage: $0 https://mixi.jp/\n"; | ||
| 26 | my $xrds = get(get_xrds_location($url))->content; | ||
| 27 | if ($xrds =~ m{<URI>([^<>]+)</URI>}) { | ||
| 28 | print "Entry point is : $1\n"; | ||
| 29 | } else { | ||
| 30 | print "xrds not found: $xrds\n"; | ||
| 31 | } | ||
| 32 | } |