X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FSet%2FPath.pm;h=259e1ce24c0dce96eb6b00a50e4a32614e350493;hb=3661d7849ae4636b74000e33e068493d90ed8337;hp=11ea1064e11b2b118c8a4f0caf989fc1db7a03b9;hpb=92147217516a40b35ca00c8e08939e8aa5478426;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/lib/LaTeX/TikZ/Set/Path.pm b/lib/LaTeX/TikZ/Set/Path.pm index 11ea106..259e1ce 100644 --- a/lib/LaTeX/TikZ/Set/Path.pm +++ b/lib/LaTeX/TikZ/Set/Path.pm @@ -5,72 +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.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; -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 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 role, and as such implements the L 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 + +Returns the TikZ code that builds a path out of the current set object as a string formatted by the L object C<$formatter>. +The current evaluation context is passed as the L object C<$context>. + +=item * + +C + +Returns a L object pointing to the beginning of the path, or C if this path has no beginning. + +=item * -use LaTeX::TikZ::Interface path => sub { - shift; +C - __PACKAGE__->new(ops => \@_); -}; +A L object pointing to the end of the path, or C if this path has no end. + +=back + +=cut + +requires qw< + path + begin + end +>; + +=head2 C + +=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, L. =head1 AUTHOR @@ -97,4 +105,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;