From: Vincent Pit Date: Thu, 27 Jan 2011 14:01:07 +0000 (+0100) Subject: Make LT::Set::Path the base role, remove ::Op, and rename the old ::Path to ::Union X-Git-Tag: rt87282~19 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=b8f42942311854cb0ef8a3e34c0145846639cd2e;p=perl%2Fmodules%2FLaTeX-TikZ.git Make LT::Set::Path the base role, remove ::Op, and rename the old ::Path to ::Union --- diff --git a/MANIFEST b/MANIFEST index a717992..01e994a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -29,13 +29,13 @@ lib/LaTeX/TikZ/Set/Arrow.pm lib/LaTeX/TikZ/Set/Circle.pm lib/LaTeX/TikZ/Set/Line.pm lib/LaTeX/TikZ/Set/Mutable.pm -lib/LaTeX/TikZ/Set/Op.pm lib/LaTeX/TikZ/Set/Path.pm lib/LaTeX/TikZ/Set/Point.pm lib/LaTeX/TikZ/Set/Polyline.pm lib/LaTeX/TikZ/Set/Raw.pm lib/LaTeX/TikZ/Set/Rectangle.pm lib/LaTeX/TikZ/Set/Sequence.pm +lib/LaTeX/TikZ/Set/Union.pm lib/LaTeX/TikZ/Tools.pm samples/synopsis.pl t/00-load.t diff --git a/lib/LaTeX/TikZ.pm b/lib/LaTeX/TikZ.pm index 61dd574..362d136 100644 --- a/lib/LaTeX/TikZ.pm +++ b/lib/LaTeX/TikZ.pm @@ -53,20 +53,20 @@ It allows you to build structures representing geometrical figures, apply a wide =head1 CONCEPTS -Traditionally, in TikZ, there are two ways of grouping elements, or I, together : +Traditionally, in TikZ, there are two ways of grouping paths together : =over 4 =item * -either as a I, where each element is drawn in its own line : +either as a I, where each path is drawn in its own line : \draw (0cm,0cm) -- (0cm,1cm) ; \draw (0cm,0cm) -- (1cm,0cm) ; =item * -or as a I, where elements are all drawn as one line : +or as an I, where paths are all drawn as one line : \draw (0cm,0cm) -- (0cm,1cm) (0cm,0cm) -- (1cm,0cm) ; @@ -74,7 +74,7 @@ or as a I, where elements are all drawn as one line : This distinction is important because there are some primitives that only apply to paths but not to sequences, and vice versa. -Figures are made of ops, path or sequence I assembled together in a tree. +Figures are made of path or sequence I assembled together in a tree. I can be applied onto any set to alter the way in which it is generated. The two TikZ concepts of I and I have been unified with the modifiers. @@ -83,9 +83,9 @@ The two TikZ concepts of I and I have been unified with the modif =head2 Containers -=head3 C<< Tikz->path(@ops) >> +=head3 C<< Tikz->union(@seq) >> -Creates a L object out of the ops C<@ops>. +Creates a L object out of the paths C<@kids>. # A path made of two circles Tikz->path( @@ -99,7 +99,7 @@ Creates a L object out of the ops C<@ops>. =head3 C<< Tikz->seq(@kids) >> -Creates a L object out of the sequences, paths or ops C<@kids>. +Creates a L object out of the sequences or paths C<@kids>. my $bag = Tikz->seq($sequence, $path, $circle, $raw, $point); diff --git a/lib/LaTeX/TikZ/Formatter.pm b/lib/LaTeX/TikZ/Formatter.pm index 77f3b53..a5bda82 100644 --- a/lib/LaTeX/TikZ/Formatter.pm +++ b/lib/LaTeX/TikZ/Formatter.pm @@ -212,10 +212,9 @@ my $find_mods = do { } } - my @subsets = $set->isa('LaTeX::TikZ::Set::Sequence') - ? $set->kids - : $set->isa('LaTeX::TikZ::Set::Path') - ? $set->ops + my @subsets = ($set->isa('LaTeX::TikZ::Set::Sequence') + || $set->isa('LaTeX::TikZ::Set::Union')) + ? $set->kids : (); $find_mods_rec->($_, $layers, $others) for @subsets; diff --git a/lib/LaTeX/TikZ/Interface.pm b/lib/LaTeX/TikZ/Interface.pm index e92888e..356a42e 100644 --- a/lib/LaTeX/TikZ/Interface.pm +++ b/lib/LaTeX/TikZ/Interface.pm @@ -69,7 +69,7 @@ sub load { require LaTeX::TikZ::Set::Raw; # raw - require LaTeX::TikZ::Set::Path; # path + require LaTeX::TikZ::Set::Union; # union require LaTeX::TikZ::Set::Sequence; # seq require LaTeX::TikZ::Set::Point; # point diff --git a/lib/LaTeX/TikZ/Mod/Clip.pm b/lib/LaTeX/TikZ/Mod/Clip.pm index 59cb2c4..1b61b4d 100644 --- a/lib/LaTeX/TikZ/Mod/Clip.pm +++ b/lib/LaTeX/TikZ/Mod/Clip.pm @@ -45,7 +45,7 @@ The path that specifies the clipped area. has clip => ( is => 'ro', - does => 'LaTeX::TikZ::Set::Op', + does => 'LaTeX::TikZ::Set::Path', required => 1, ); diff --git a/lib/LaTeX/TikZ/Set/Circle.pm b/lib/LaTeX/TikZ/Set/Circle.pm index d1f7317..54c1540 100644 --- a/lib/LaTeX/TikZ/Set/Circle.pm +++ b/lib/LaTeX/TikZ/Set/Circle.pm @@ -27,11 +27,11 @@ use Any::Moose 'Util::TypeConstraints'; =head1 RELATIONSHIPS -This class consumes the L role, and as such implements the L method. +This class consumes the L role, and as such implements the L method. =cut -with 'LaTeX::TikZ::Set::Op'; +with 'LaTeX::TikZ::Set::Path'; =head1 ATTRIBUTES @@ -95,7 +95,7 @@ __PACKAGE__->meta->make_immutable; =head1 SEE ALSO -L, L, L. +L, L, L. =head1 AUTHOR diff --git a/lib/LaTeX/TikZ/Set/Line.pm b/lib/LaTeX/TikZ/Set/Line.pm index 3ee9694..4054bfd 100644 --- a/lib/LaTeX/TikZ/Set/Line.pm +++ b/lib/LaTeX/TikZ/Set/Line.pm @@ -24,11 +24,11 @@ use Any::Moose; =head1 RELATIONSHIPS -This class consumes the L role, and as such implements the L method. +This class consumes the L role, and as such implements the L method. =cut -with 'LaTeX::TikZ::Set::Op'; +with 'LaTeX::TikZ::Set::Path'; =head1 ATTRIBUTES @@ -89,7 +89,7 @@ __PACKAGE__->meta->make_immutable; =head1 SEE ALSO -L, L. +L, L. =head1 AUTHOR diff --git a/lib/LaTeX/TikZ/Set/Op.pm b/lib/LaTeX/TikZ/Set/Op.pm deleted file mode 100644 index 69d8a63..0000000 --- a/lib/LaTeX/TikZ/Set/Op.pm +++ /dev/null @@ -1,95 +0,0 @@ -package LaTeX::TikZ::Set::Op; - -use strict; -use warnings; - -=head1 NAME - -LaTeX::TikZ::Set::Op - A role for set objects that can be part of a path. - -=head1 VERSION - -Version 0.02 - -=cut - -our $VERSION = '0.02'; - -=head1 DESCRIPTION - -Ops are the components of a path. -They can be built together to form a path. -Thus, they are all the elements against which we can call the C method. - -=cut - -use Any::Moose 'Role'; - -=head1 RELATIONSHIPS - -This role consumes the L role, and as such implements the L method. - -=cut - -with 'LaTeX::TikZ::Set'; - -=head1 METHODS - -This method is required by the interface : - -=over 4 - -=item * - -C - -Returns the TikZ code that builds a path out of the current set object as a string formatted by the L object C<$formatter>. - -=back - -=cut - -requires qw< - path ->; - -=head2 C - -=cut - -sub draw { - my $set = shift; - - [ "\\draw " . $set->path(@_) . ' ;' ]; -} - -=head1 SEE ALSO - -L, L. - -=head1 AUTHOR - -Vincent Pit, C<< >>, L. - -You can contact me by mail or on C (vincent). - -=head1 BUGS - -Please report any bugs or feature requests to C, or through the web interface at L. -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::Op; diff --git a/lib/LaTeX/TikZ/Set/Path.pm b/lib/LaTeX/TikZ/Set/Path.pm index a19d8c0..f7a5fb2 100644 --- a/lib/LaTeX/TikZ/Set/Path.pm +++ b/lib/LaTeX/TikZ/Set/Path.pm @@ -5,7 +5,7 @@ use warnings; =head1 NAME -LaTeX::TikZ::Set::Path - A set object representing a path. +LaTeX::TikZ::Set::Path - A role for set objects that can be part of a path. =head1 VERSION @@ -15,89 +15,55 @@ Version 0.02 our $VERSION = '0.02'; -use LaTeX::TikZ::Interface; -use LaTeX::TikZ::Functor; +=head1 DESCRIPTION -use LaTeX::TikZ::Tools; - -use Any::Moose; - -=head1 RELATIONSHIPS - -This class consumes the L and L roles, and as such implements the L and L methods. +Paths are all the elements against which we can call the C method. =cut -with qw< - LaTeX::TikZ::Set::Op - LaTeX::TikZ::Set::Mutable ->; +use Any::Moose 'Role'; -=head1 ATTRIBUTES - -=head2 C +=head1 RELATIONSHIPS -The L objects that from the path. +This role consumes the L role, and as such implements the L method. =cut -has '_ops' => ( - is => 'ro', - isa => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Op]]', - init_arg => 'ops', - default => sub { [ ] }, -); - -sub ops { @{$_[0]->_ops} } +with 'LaTeX::TikZ::Set'; =head1 METHODS -=head2 C +This method is required by the interface : -=cut +=over 4 -my $ltso_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Set::Op'); +=item * -sub add { - my $set = shift; +C - $ltso_tc->assert_valid($_) for @_; +Returns the TikZ code that builds a path out of the current set object as a string formatted by the L object C<$formatter>. - push @{$set->_ops}, @_; +=back - $set; -} +=cut + +requires qw< + path +>; -=head2 C +=head2 C =cut -sub path { +sub draw { my $set = shift; - join ' ', map $_->path(@_), $set->ops; + [ "\\draw " . $set->path(@_) . ' ;' ]; } -LaTeX::TikZ::Interface->register( - path => sub { - shift; - - __PACKAGE__->new(ops => \@_); - }, -); - -LaTeX::TikZ::Functor->default_rule( - (__PACKAGE__) => sub { - my ($functor, $set, @args) = @_; - $set->new(ops => [ map $_->$functor(@args), $set->ops ]) - } -); - -__PACKAGE__->meta->make_immutable; - =head1 SEE ALSO -L, L, L. +L, L. =head1 AUTHOR @@ -124,4 +90,4 @@ This program is free software; you can redistribute it and/or modify it under th =cut -1; # End of LaTeX::TikZ::Set::Path +1; # End of LaTeX::TikZ::Set::Path; diff --git a/lib/LaTeX/TikZ/Set/Point.pm b/lib/LaTeX/TikZ/Set/Point.pm index 2309db3..d5761d1 100644 --- a/lib/LaTeX/TikZ/Set/Point.pm +++ b/lib/LaTeX/TikZ/Set/Point.pm @@ -25,11 +25,11 @@ use Any::Moose 'Util::TypeConstraints'; =head1 RELATIONSHIPS -This class consumes the L role, and as such implements the L method. +This class consumes the L role, and as such implements the L method. =cut -with 'LaTeX::TikZ::Set::Op'; +with 'LaTeX::TikZ::Set::Path'; =head1 ATTRIBUTES @@ -146,7 +146,7 @@ __PACKAGE__->meta->make_immutable; =head1 SEE ALSO -L, L. +L, L. =head1 AUTHOR diff --git a/lib/LaTeX/TikZ/Set/Polyline.pm b/lib/LaTeX/TikZ/Set/Polyline.pm index dbd9b0a..a1992a5 100644 --- a/lib/LaTeX/TikZ/Set/Polyline.pm +++ b/lib/LaTeX/TikZ/Set/Polyline.pm @@ -25,11 +25,11 @@ use Any::Moose 'Util::TypeConstraints'; =head1 RELATIONSHIPS -This class consumes the L role, and as such implements the L method. +This class consumes the L role, and as such implements the L method. =cut -with 'LaTeX::TikZ::Set::Op'; +with 'LaTeX::TikZ::Set::Path'; subtype 'LaTeX::TikZ::Set::Polyline::Vertices' => as 'ArrayRef[LaTeX::TikZ::Set::Point]' @@ -110,7 +110,7 @@ __PACKAGE__->meta->make_immutable; =head1 SEE ALSO -L, L. +L, L. =head1 AUTHOR diff --git a/lib/LaTeX/TikZ/Set/Raw.pm b/lib/LaTeX/TikZ/Set/Raw.pm index 159492d..68f4025 100644 --- a/lib/LaTeX/TikZ/Set/Raw.pm +++ b/lib/LaTeX/TikZ/Set/Raw.pm @@ -22,11 +22,11 @@ use Any::Moose; =head1 RELATIONSHIPS -This class consumes the L role, and as such implements the L method. +This class consumes the L role, and as such implements the L method. =cut -with 'LaTeX::TikZ::Set::Op'; +with 'LaTeX::TikZ::Set::Path'; =head1 ATTRIBUTES @@ -69,7 +69,7 @@ __PACKAGE__->meta->make_immutable; =head1 SEE ALSO -L, L. +L, L. =head1 AUTHOR diff --git a/lib/LaTeX/TikZ/Set/Rectangle.pm b/lib/LaTeX/TikZ/Set/Rectangle.pm index c672939..2e290db 100644 --- a/lib/LaTeX/TikZ/Set/Rectangle.pm +++ b/lib/LaTeX/TikZ/Set/Rectangle.pm @@ -24,11 +24,11 @@ use Any::Moose; =head1 RELATIONSHIPS -This class consumes the L role, and as such implements the L method. +This class consumes the L role, and as such implements the L method. =cut -with 'LaTeX::TikZ::Set::Op'; +with 'LaTeX::TikZ::Set::Path'; =head1 ATTRIBUTES @@ -154,7 +154,7 @@ __PACKAGE__->meta->make_immutable; =head1 SEE ALSO -L, L. +L, L. =head1 AUTHOR diff --git a/lib/LaTeX/TikZ/Set/Sequence.pm b/lib/LaTeX/TikZ/Set/Sequence.pm index 446721e..c453121 100644 --- a/lib/LaTeX/TikZ/Set/Sequence.pm +++ b/lib/LaTeX/TikZ/Set/Sequence.pm @@ -40,7 +40,7 @@ with qw< subtype 'LaTeX::TikZ::Set::Sequence::Elements' => as 'Object' => where { - $_->does('LaTeX::TikZ::Set::Op') + $_->does('LaTeX::TikZ::Set::Path') or $_->isa('LaTeX::TikZ::Set::Sequence') }; @@ -48,7 +48,7 @@ subtype 'LaTeX::TikZ::Set::Sequence::Elements' =head2 C -The L or L objects that from the sequence. +The L or L objects that from the sequence. =cut @@ -113,7 +113,7 @@ __PACKAGE__->meta->make_immutable; =head1 SEE ALSO -L, L, L. +L, L, L. =head1 AUTHOR diff --git a/lib/LaTeX/TikZ/Set/Union.pm b/lib/LaTeX/TikZ/Set/Union.pm new file mode 100644 index 0000000..2648d3d --- /dev/null +++ b/lib/LaTeX/TikZ/Set/Union.pm @@ -0,0 +1,127 @@ +package LaTeX::TikZ::Set::Union; + +use strict; +use warnings; + +=head1 NAME + +LaTeX::TikZ::Set::Union - A set object representing a path formed by the reunion of several subpaths. + +=head1 VERSION + +Version 0.02 + +=cut + +our $VERSION = '0.02'; + +use LaTeX::TikZ::Interface; +use LaTeX::TikZ::Functor; + +use LaTeX::TikZ::Tools; + +use Any::Moose; + +=head1 RELATIONSHIPS + +This class consumes the L and L roles, and as such implements the L and L methods. + +=cut + +with qw< + LaTeX::TikZ::Set::Path + LaTeX::TikZ::Set::Mutable +>; + +=head1 ATTRIBUTES + +=head2 C + +The L objects that form the path. + +=cut + +has '_kids' => ( + is => 'ro', + isa => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Path]]', + init_arg => 'kids', + default => sub { [ ] }, +); + +sub kids { @{$_[0]->_kids} } + +=head1 METHODS + +=head2 C + +=cut + +my $ltsp_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Set::Path'); + +sub add { + my $set = shift; + + $ltsp_tc->assert_valid($_) for @_; + + push @{$set->_kids}, @_; + + $set; +} + +=head2 C + +=cut + +sub path { + my $set = shift; + + join ' ', map $_->path(@_), $set->kids; +} + +LaTeX::TikZ::Interface->register( + union => sub { + shift; + + __PACKAGE__->new(kids => \@_); + }, +); + +LaTeX::TikZ::Functor->default_rule( + (__PACKAGE__) => sub { + my ($functor, $set, @args) = @_; + $set->new(kids => [ map $_->$functor(@args), $set->kids ]) + } +); + +__PACKAGE__->meta->make_immutable; + +=head1 SEE ALSO + +L, L, L. + +=head1 AUTHOR + +Vincent Pit, C<< >>, L. + +You can contact me by mail or on C (vincent). + +=head1 BUGS + +Please report any bugs or feature requests to C, or through the web interface at L. +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::Union diff --git a/t/00-load.t b/t/00-load.t index a0af7c6..a821174 100644 --- a/t/00-load.t +++ b/t/00-load.t @@ -32,13 +32,13 @@ BEGIN { use_ok( 'LaTeX::TikZ::Set::Circle' ); use_ok( 'LaTeX::TikZ::Set::Line' ); use_ok( 'LaTeX::TikZ::Set::Mutable' ); - use_ok( 'LaTeX::TikZ::Set::Op' ); use_ok( 'LaTeX::TikZ::Set::Path' ); use_ok( 'LaTeX::TikZ::Set::Point' ); use_ok( 'LaTeX::TikZ::Set::Polyline' ); use_ok( 'LaTeX::TikZ::Set::Raw' ); use_ok( 'LaTeX::TikZ::Set::Rectangle' ); use_ok( 'LaTeX::TikZ::Set::Sequence' ); + use_ok( 'LaTeX::TikZ::Set::Union' ); use_ok( 'LaTeX::TikZ::Tools' ); } diff --git a/t/01-api.t b/t/01-api.t index dd098d9..b0d7b20 100644 --- a/t/01-api.t +++ b/t/01-api.t @@ -31,7 +31,7 @@ is(prototype('Tikz'), '', 'main::Tikz is actually a constant'); my @methods = qw< formatter functor raw - path seq + union seq point line polyline closed_polyline rectangle circle arc arrow raw_mod clip layer diff --git a/t/10-set.t b/t/10-set.t index 5ec0e33..9d20422 100644 --- a/t/10-set.t +++ b/t/10-set.t @@ -157,15 +157,15 @@ sub failed_valid { } eval { - Tikz->path($foo, $seq2); + Tikz->union($foo, $seq2); }; -like $@, failed_valid('Maybe[ArrayRef[LaTeX::TikZ::Set::Op]]'), - 'creating a path that contains a sequence croaks'; +like $@, failed_valid('Maybe[ArrayRef[LaTeX::TikZ::Set::Path]]'), + 'creating an union that contains a sequence croaks'; my $path = eval { - Tikz->path($foo, $bar, $baz); + Tikz->union($foo, $bar, $baz); }; -is $@, '', 'creating a path set doesn\'t croak'; +is $@, '', 'creating an union set doesn\'t croak'; check $path, 'one path set', <<'RES'; \draw foo bar baz ; @@ -184,5 +184,5 @@ RES eval { $path->add($seq2); }; -like $@, failed_valid('LaTeX::TikZ::Set::Op'), +like $@, failed_valid('LaTeX::TikZ::Set::Path'), 'adding a sequence to a path croaks'; diff --git a/t/30-functor.t b/t/30-functor.t index 64d7d4b..a5952ef 100644 --- a/t/30-functor.t +++ b/t/30-functor.t @@ -122,7 +122,7 @@ $special = eval { '+LaTeX::TikZ::Mod' => sub { die "mod\n" }, '+LaTeX::TikZ::Set' => sub { die "set\n" }, 'LaTeX::TikZ::Set::Point' => sub { Tikz->point(7) }, - 'LaTeX::TikZ::Set::Op' => sub { Tikz->raw('moo') }, + 'LaTeX::TikZ::Set::Path' => sub { Tikz->raw('moo') }, ); }; is $@, '', 'creating a special functor with + and normal rules doesn\'t croak'; diff --git a/t/92-pod-coverage.t b/t/92-pod-coverage.t index bf0ee70..f6cc91b 100644 --- a/t/92-pod-coverage.t +++ b/t/92-pod-coverage.t @@ -47,11 +47,11 @@ pod_coverage_ok( 'LaTeX::TikZ::Set::Arrow' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Circle' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Line' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Mutable' ); -pod_coverage_ok( 'LaTeX::TikZ::Set::Op' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Path' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Point' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Polyline' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Raw' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Rectangle' ); pod_coverage_ok( 'LaTeX::TikZ::Set::Sequence' ); +pod_coverage_ok( 'LaTeX::TikZ::Set::Union' ); pod_coverage_ok( 'LaTeX::TikZ::Tools' );