#!/usr/bin/perl

use strict;
use warnings;


use feature qw/say switch/;

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

foreach my $domain (@input) {
    my @keys;
    given ($domain) {
        when (/\.?xn--/) {
            @keys = qw/domain zone/;
        }
        default {
            @keys = qw/domain_ace zone_ace/;
        }
    }
    my $parsed = parse_domain($domain);
    say join "." => @{$parsed}{@keys};
}
exit(0);


__END__

=head1 NAME

    convertpuny - Commandline puny en/decoder.

=head1 USAGE

    convertpuny 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.


