#!perl -w

use strict;
#use warnings;
use Carp qw(croak);
use CSS::Janus;
use Getopt::Long;
use Pod::Usage;

my $debug;
my $src;
my $dest;
my $swap_ltr_rtl_in_url;
my $flip_cursor;
my $flip_url;
my $ignore_bad_bgp;

use vars qw($VERSION);
$VERSION = '0.04_02';

unless (
    GetOptions 'h|help' => sub {
	pod2usage(-verbose => 2, -exitval => 0);
    },
    'version' => sub {
	print "cssflip $VERSION\n";
	exit;
    },
    'debug'                  => \$debug,
    's|src|source=s'         => \$src,
    'd|dest|destination=s'   => \$dest,
    'swap_ltr_rtl_in_url'    => \$swap_ltr_rtl_in_url,
    'swap_left_right_in_url' => \$flip_url,
    'ignore_bad_bgp'         => \$ignore_bad_bgp,
    'flip_url'               => \$flip_url,
    'flip_cursor!'           => \$flip_cursor,
    ) {
    pod2usage(-verbose => 1, -output => \*STDERR, -exitval => 1);
}

unless ($src or $dest) {
    print CSS::Janus->new(
	'debug'                  => $debug,
	'swap_ltr_rtl_in_url'    => $swap_ltr_rtl_in_url,
	'swap_left_right_in_url' => $flip_url,
	'ignore_bad_bgp'         => $ignore_bad_bgp,
    )->transform(join '', <>);
} elsif ($src and $dest) {
    print CSS::Yamaantaka->new(
        'debug'               => $debug,
	$src                  => $dest,
	'swap_ltr_rtl_in_url' => $swap_ltr_rtl_in_url,
	'flip_url'            => $flip_url,
	'ignore_bad_bgp'      => $ignore_bad_bgp,
	'flip_cursor'         => $flip_cursor,
    )->transform(join '', <>);
} else {
    pod2usage(-verbose => 1, -output => \*STDERR, -exitval => 1);
}

__END__

=head1 NAME

cssflip - Flip direction of Cascading Style Sheet (CSS)

=head1 SYNOPSIS

  cssflip [ options ... ] file.css ... > file-rtl.css

=head1 DESCRIPTION

=head2 Options

=over 4

=item --src=SRC --dest=DEST

Original and resulting directions.
Available directions are
C<'lr_tb'>, C<'rl_tb'>, C<'tb_lr'> and C<'tb_rl'>.
Their synonyms are C<'ltr'>, C<'rtl'>, C<'vertical-lr'> and C<'vertical-rl'>,

If directions are not specified, swaps between ltr and rtl.

=item --flip_url

Fixes "left"/"right" string within URLs.
Synonym is --swap_left_right_in_url.

=item --swap_ltr_rtl_in_url

Fixes "ltr"/"rtl" string within URLs.

=item --ignore_bad_bgp

Ignores unmirrorable background-position values.

=item --noflip_cursor

Doesn't fix positions "n"/"e"/"s"/"w" and so on within cursor properties.

=back

=head1 VERSION

Run "C<cssflip --version>".

=head1 AUTHOR

Hatuka*nezumi - IKEDA Soji <hatuka(at)nezumi.nu>

=head1 COPYRIGHT

Copyright (C) 2013 Hatuka*nezumi - IKEDA Soji.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut