package LaTeX::TikZ::Set;

use strict;
use warnings;

=head1 NAME

LaTeX::TikZ::Set - Base role for LaTeX::TikZ set objects.

=head1 VERSION

Version 0.01

=cut

our $VERSION = '0.01';

use LaTeX::TikZ::Set::Mod;

use LaTeX::TikZ::Tools;

use Any::Moose 'Role';

requires qw(
 draw
);

sub mod {
 my $set = $_[0];

 return $set unless @_ > 1;

 # If $set is already a Tikz::Set::Mod object, the overridden method is
 # called instead. This ensures that you can't have two T::S::M objects in a
 # row.

 # Prepend a new set with the mods
 my $new = LaTeX::TikZ::Set::Mod->new(
  set  => $set,
  mods => [ @_[1 .. $#_] ],
 );

 $_[0] = $new unless defined wantarray;

 $new;
}

my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip');

sub layer {
 return $_[0] unless @_ > 1;

 my $layer = $_[1];

 $_[0]->mod(
  $ltml_tc->check($layer) ? $layer
                          : LaTeX::TikZ::Mod::Layer->new(name => $layer)
 )
}

sub clip {
 return $_[0] unless @_ > 1;

 $_[0]->mod(
  map {
   $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new($_)
  } @_[1 .. $#_]
 )
}

=head1 AUTHOR

Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.

You can contact me by mail or on C<irc.perl.org> (vincent).

=head1 BUGS

Please report any bugs or feature requests to C<bug-latex-tikz at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LaTeX-TikZ>.
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc LaTeX::TikZ

=head1 COPYRIGHT & LICENSE

Copyright 2010 Vincent Pit, all rights reserved.

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

=cut

1; # End of LaTeX::TikZ::Set
