| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
|
| 5 |
BEGIN |
| 6 |
{ |
| 7 |
print STDERR "Reading vCard input from STDIN.\n" |
| 8 |
unless @ARGV; |
| 9 |
} |
| 10 |
|
| 11 |
use RDF::vCard; |
| 12 |
use XML::LibXML; |
| 13 |
|
| 14 |
my $importer = RDF::vCard::Importer->new; |
| 15 |
my @cards; |
| 16 |
|
| 17 |
unless (@ARGV) |
| 18 |
{ |
| 19 |
my ($lang) = split /\./, $ENV{LANG}; |
| 20 |
$lang =~ s/_/-/g; |
| 21 |
|
| 22 |
local $/ = undef; |
| 23 |
my $input = <>; |
| 24 |
|
| 25 |
push @cards, $importer->import_string($input, lang => $lang); |
| 26 |
} |
| 27 |
|
| 28 |
while (my $input = shift @ARGV) |
| 29 |
{ |
| 30 |
if ($input =~ /^(ftp|http|https|file):/i) |
| 31 |
{ |
| 32 |
push @cards, $importer->import_url($input); |
| 33 |
} |
| 34 |
else |
| 35 |
{ |
| 36 |
push @cards, $importer->import_file($input); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
my $doc; |
| 41 |
foreach my $c (@cards) |
| 42 |
{ |
| 43 |
if ($doc) |
| 44 |
{ |
| 45 |
$c->add_to_document($doc); |
| 46 |
} |
| 47 |
else |
| 48 |
{ |
| 49 |
die "No XML support available (please install XML::LibXML)\n" |
| 50 |
unless $c->can('to_xml'); |
| 51 |
# Kinda annoying that we only get it as a string, and then need to parse it as XML. :-( |
| 52 |
$doc = XML::LibXML->new->parse_string($c->to_xml); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
printf("%s\n", $doc->toString) if $doc; |