]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set/Path.pm
Make LT::Set::Path the base role, remove ::Op, and rename the old ::Path to ::Union
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Path.pm
index a19d8c0ff436c879911fa2f70a236d63f92be8f0..f7a5fb21b684deb1afca328d216f41597d42db27 100644 (file)
@@ -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<LaTeX::TikZ::Set::Op> and L<LaTeX::TikZ::Set::Mutable> roles, and as such implements the L</path> and L</add> methods.
+Paths are all the elements against which we can call the C<path> method.
 
 =cut
 
-with qw<
- LaTeX::TikZ::Set::Op
- LaTeX::TikZ::Set::Mutable
->;
+use Any::Moose 'Role';
 
-=head1 ATTRIBUTES
-
-=head2 C<ops>
+=head1 RELATIONSHIPS
 
-The L<LaTeX::TikZ::Set::Op> objects that from the path.
+This role consumes the L<LaTeX::TikZ::Set> role, and as such implements the L</draw> 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<add>
+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<path $formatter>
 
- $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<LaTeX::TikZ::Formatter> object C<$formatter>.
 
- push @{$set->_ops}, @_;
+=back
 
- $set;
-}
+=cut
+
+requires qw<
+ path
+>;
 
-=head2 C<path>
+=head2 C<draw>
 
 =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<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Op>, L<LaTeX::TikZ::Set::Mutable>.
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set>.
 
 =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;