#!/usr/bin/perl

# Copyright © 2014 Jonas Smedegaard <dr@jones.dk>
# Description: optimize internal structure of SVG files
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Depends: libxml-twig-perl
#
# TODO: Apply (the equivalent of) python-scour

use warnings;
use strict;

use XML::Twig;

my $twig = XML::Twig->new(
	keep_encoding => 1,
	keep_atts_order => 1,
	pretty_print => 'indented',
	twig_handlers => {
		_all_ => sub { $_[0]->flush; },
	}
);

$twig->set_indent("\t");

if ( my $file= $ARGV[0] ) {
	$twig->parsefile( $file);
} else {
	$twig->parse( \*STDIN);
}

$twig->flush;

1;