]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set.pm
Initial commit
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set.pm
1 package LaTeX::TikZ::Set;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 LaTeX::TikZ::Set - Base role for LaTeX::TikZ set objects.
9
10 =head1 VERSION
11
12 Version 0.01
13
14 =cut
15
16 our $VERSION = '0.01';
17
18 use LaTeX::TikZ::Set::Mod;
19
20 use LaTeX::TikZ::Tools;
21
22 use Any::Moose 'Role';
23
24 requires qw(
25  draw
26 );
27
28 sub mod {
29  my $set = $_[0];
30
31  return $set unless @_ > 1;
32
33  # If $set is already a Tikz::Set::Mod object, the overridden method is
34  # called instead. This ensures that you can't have two T::S::M objects in a
35  # row.
36
37  # Prepend a new set with the mods
38  my $new = LaTeX::TikZ::Set::Mod->new(
39   set  => $set,
40   mods => [ @_[1 .. $#_] ],
41  );
42
43  $_[0] = $new unless defined wantarray;
44
45  $new;
46 }
47
48 my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
49 my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip');
50
51 sub layer {
52  return $_[0] unless @_ > 1;
53
54  my $layer = $_[1];
55
56  $_[0]->mod(
57   $ltml_tc->check($layer) ? $layer
58                           : LaTeX::TikZ::Mod::Layer->new(name => $layer)
59  )
60 }
61
62 sub clip {
63  return $_[0] unless @_ > 1;
64
65  $_[0]->mod(
66   map {
67    $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new($_)
68   } @_[1 .. $#_]
69  )
70 }
71
72 =head1 AUTHOR
73
74 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
75
76 You can contact me by mail or on C<irc.perl.org> (vincent).
77
78 =head1 BUGS
79
80 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>.
81 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
82
83 =head1 SUPPORT
84
85 You can find documentation for this module with the perldoc command.
86
87     perldoc LaTeX::TikZ
88
89 =head1 COPYRIGHT & LICENSE
90
91 Copyright 2010 Vincent Pit, all rights reserved.
92
93 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
94
95 =cut
96
97 1; # End of LaTeX::TikZ::Set