#!/usr/bin/perl

use strict;
use warnings;

use feature qw/say switch/;

use ParseUtil::Domain ':simple';
binmode( STDOUT, "utf8" );
binmode( STDERR, "utf8" );
binmode( STDIN,  "utf8" );
my @input;
if (@ARGV) {
    @input = @ARGV;
}
else {
    @input = <>;
}

foreach my $domain (@input) {
    chomp $domain;
    my $parsed;
    local $@;
    eval { say puny_convert($domain); };
    if ( my $e = $@ ) {
        print STDERR "# " . $domain . ":\t" . $e;
    }
}
exit(0);

__END__

=head1 NAME

    punyconvert - Commandline puny en/decoder.

=head1 USAGE

    punyconvert xn--fa-hia.de
    faß.de

=head1 DESCRIPTION

    This just converts domains to and from puny encoding. Useful for
    commandline and or batch operations with text files.