]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set/Path.pm
This is 0.03
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Path.pm
index 5a9e59c283432bd5b814cb52fc4b28fd15ba22a9..9dbc902eaa70e0d3a035412660180a3c753216da 100644 (file)
@@ -5,75 +5,80 @@ 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
 
-Version 0.01
+Version 0.03
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.03';
 
-use LaTeX::TikZ::Interface;
-use LaTeX::TikZ::Functor;
+=head1 DESCRIPTION
 
-use Any::Moose;
-use Any::Moose 'Util::TypeConstraints'
-               => [ qw/subtype as where find_type_constraint/ ];
+Paths are all the elements against which we can call the C<path> method.
 
-with qw(
- LaTeX::TikZ::Set::Op
- LaTeX::TikZ::Set::Mutable
-);
+=cut
 
-subtype 'LaTeX::TikZ::Set::Path::Elements'
-     => as 'Object'
-     => where { $_->does('LaTeX::TikZ::Set::Op') };
+use Mouse::Role;
 
-has '_ops' => (
- is       => 'ro',
- isa      => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Path::Elements]]',
- init_arg => 'ops',
- default  => sub { [ ] },
-);
+=head1 RELATIONSHIPS
 
-sub ops { @{$_[0]->_ops} }
+This role consumes the L<LaTeX::TikZ::Set> role, and as such implements the L</draw> method.
 
-my $ltspe_tc = find_type_constraint('LaTeX::TikZ::Set::Path::Elements');
+=cut
 
-sub add {
- my $set = shift;
+with 'LaTeX::TikZ::Set';
 
- $ltspe_tc->assert_valid($_) for @_;
+=head1 METHODS
 
- push @{$set->_ops}, @_;
+These methods are required by the interface :
 
- $set;
-}
+=over 4
 
-sub path {
- my $set = shift;
+=item *
 
- join ' ', map $_->path(@_), $set->ops;
-}
+C<path $formatter, $context>
+
+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>.
+The current evaluation context is passed as the L<LaTeX::TikZ::Context> object C<$context>.
+
+=item *
+
+C<begin>
+
+Returns a L<LaTeX::TikZ::Point> object pointing to the beginning of the path, or C<undef> if this path has no beginning.
+
+=item *
 
-LaTeX::TikZ::Interface->register(
- path => sub {
-  shift;
+C<end>
 
-  __PACKAGE__->new(ops => \@_);
- },
-);
+A L<LaTeX::TikZ::Point> object pointing to the end of the path, or C<undef> if this path has no end.
+
+=back
+
+=cut
+
+requires qw<
+ path
+ begin
+ end
+>;
+
+=head2 C<draw>
+
+=cut
+
+sub draw {
+ my $set = shift;
+
+ [ "\\draw " . $set->path(@_) . ' ;' ];
+}
 
-LaTeX::TikZ::Functor->default_rule(
- (__PACKAGE__) => sub {
-  my ($functor, $set, @args) = @_;
-  $set->new(ops => [ map $_->$functor(@args), $set->ops ])
- }
-);
+=head1 SEE ALSO
 
-__PACKAGE__->meta->make_immutable;
+L<LaTeX::TikZ>, L<LaTeX::TikZ::Set>.
 
 =head1 AUTHOR
 
@@ -94,10 +99,10 @@ You can find documentation for this module with the perldoc command.
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2010 Vincent Pit, all rights reserved.
+Copyright 2010,2011,2012,2013,2014,2015 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::Path
+1; # End of LaTeX::TikZ::Set::Path;