Browse Source

more robust

David Sniperovitch 8 years ago
parent
commit
89544ddfc5
1 changed files with 14 additions and 7 deletions
  1. 14 7
      mirror_pad.pl

+ 14 - 7
mirror_pad.pl

@@ -8,16 +8,23 @@ use Encode ();
 use FindBin;
 use FindBin;
 use URI::Encode ();
 use URI::Encode ();
 
 
-my $url = URI::Encode::uri_decode(shift);
-my $c = Config::YAML->new(config => "$FindBin::Bin/mirror_pad.yml");
+my $pad_url = URI::Encode::uri_decode(shift);
+warn "PAD_URL=$pad_url";
+
+my $config_file = "$FindBin::Bin/mirror_pad.yml";
+die "'$config_file' introuvable\n" unless -r $config_file;
+
+my $c = Config::YAML->new(config => $config_file);
 my $ep = Etherpad->new(
 my $ep = Etherpad->new(
-  url      => $c->get_url,
-  apikey   => $c->get_apikey,
+  apiurl => $c->get_apiurl,
+  apikey => $c->get_apikey,
 );
 );
 
 
-my $pad_base = quotemeta $c->get_url;
-my $pad_id = $url;
-$pad_id =~ s{$pad_base/.+?/(g\.[^/]+).*$}{$1};
+my $pad_base = quotemeta $c->get_apiurl;
+warn "PAD_BASE=$pad_base";
+# Extraction de l'id du pad à partir de l'url du pad
+my $pad_id;
+($pad_id) = $pad_url =~ m{^$pad_base/.+?/(g\.[^/]+)}o;
 warn "PADID=$pad_id\n";
 warn "PADID=$pad_id\n";
 if(my($pad_text) = $ep->get_text($pad_id)) {
 if(my($pad_text) = $ep->get_text($pad_id)) {
     $pad_text = Encode::encode('UTF-8', $pad_text);
     $pad_text = Encode::encode('UTF-8', $pad_text);