summaryrefslogtreecommitdiff
path: root/localvcard2rdf
blob: 33059b41c053d2570f3881b542e2f901cfb7b881 (plain)
  1. #!/usr/bin/perl
  2. # Copyright © 2014-2015 Jonas Smedegaard <dr@jones.dk>
  3. # Description: Recode vCard file(s) or STDIN to RDF/Turtle on STDOUT
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3, or (at your option)
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # Depends: librdf-vcard-perl librdf-trinex-serializer-mockturtlesoup-perl
  19. use strict;
  20. use warnings;
  21. use RDF::vCard;
  22. use RDF::TrineX::Serializer::MockTurtleSoup;
  23. BEGIN
  24. {
  25. print STDERR "Reading vCard input from STDIN.\n"
  26. unless @ARGV;
  27. }
  28. my $importer = RDF::vCard::Importer->new;
  29. unless (@ARGV) {
  30. my ($lang) = split /\./, $ENV{LANG};
  31. $lang =~ s/_/-/g;
  32. local $/ = undef;
  33. my $input = <>;
  34. $importer->import_string($input, lang => $lang);
  35. }
  36. while (my $input = shift @ARGV) {
  37. if ($input =~ /^(ftp|http|https|file):/i)
  38. {
  39. $importer->import_url($input);
  40. }
  41. else
  42. {
  43. $importer->import_file($input);
  44. }
  45. }
  46. my $ser = "RDF::TrineX::Serializer::MockTurtleSoup"->new({colspace => 0});
  47. print $ser->serialize_model_to_string($importer->model);