#!/usr/bin/env perl -w    # -*- cperl; cperl-indent-level: 4 -*-
# Copyright (C) 2009-2018, Roland van Ipenburg
use strict;
use warnings;

use utf8;
use 5.014000;
use English qw( -no_match_vars );
BEGIN { our $VERSION = v1.1.1; }

use HTML::Hyphenate;

use Readonly;
## no critic qw(ProhibitCallsToUnexportedSubs)
Readonly::Scalar my $MIN_LENGTH => 5;
## use critic

my $hyphenator = HTML::Hyphenate->new();
$hyphenator->min_length($MIN_LENGTH);

while ( my $filename = shift @ARGV ) {
    open( my $fh, q{<:encoding(UTF-8)}, $filename )
      ## no critic qw(RequireCarping RequireUseOfExceptions)
      || die qq{Can't open UTF-8 encoded $filename: $ERRNO};
    ## use critic
    my $html = q{};
    while ( my $line = <$fh> ) {
        $html .= $line;
    }
    ## no critic qw(RequireCarping RequireUseOfExceptions)
    close $fh || die qq{Can't close UTF-8 encoded $fh: $ERRNO};
    ## use critic
    binmode STDOUT, ':encoding(UTF-8)';
    ## no critic qw(RequireCheckedSyscalls)
    print $hyphenator->hyphenated($html);
    ## use critic
}
