]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Path.pm
Introduce LaTeX::TikZ::Functor
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Path.pm
1 package LaTeX::TikZ::Set::Path;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 LaTeX::TikZ::Set::Path - A set object representing a path.
9
10 =head1 VERSION
11
12 Version 0.01
13
14 =cut
15
16 our $VERSION = '0.01';
17
18 use LaTeX::TikZ::Functor;
19
20 use Any::Moose;
21 use Any::Moose 'Util::TypeConstraints'
22                => [ qw/subtype as where find_type_constraint/ ];
23
24 with qw(
25  LaTeX::TikZ::Set::Op
26  LaTeX::TikZ::Set::Mutable
27 );
28
29 subtype 'LaTeX::TikZ::Set::Path::Elements'
30      => as 'Object'
31      => where { $_->does('LaTeX::TikZ::Set::Op') };
32
33 has '_ops' => (
34  is       => 'ro',
35  isa      => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Path::Elements]]',
36  init_arg => 'ops',
37  default  => sub { [ ] },
38 );
39
40 sub ops { @{$_[0]->_ops} }
41
42 my $ltspe_tc = find_type_constraint('LaTeX::TikZ::Set::Path::Elements');
43
44 sub add {
45  my $set = shift;
46
47  $ltspe_tc->assert_valid($_) for @_;
48
49  push @{$set->_ops}, @_;
50
51  $set;
52 }
53
54 sub path {
55  my $set = shift;
56
57  join ' ', map $_->path(@_), $set->ops;
58 }
59
60 use LaTeX::TikZ::Interface path => sub {
61  shift;
62
63  __PACKAGE__->new(ops => \@_);
64 };
65
66 LaTeX::TikZ::Functor->default_rule(
67  (__PACKAGE__) => sub {
68   my ($functor, $set, @args) = @_;
69   $set->new(ops => [ map $_->$functor(@args), $set->ops ])
70  }
71 );
72
73 __PACKAGE__->meta->make_immutable;
74
75 =head1 AUTHOR
76
77 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
78
79 You can contact me by mail or on C<irc.perl.org> (vincent).
80
81 =head1 BUGS
82
83 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>.
84 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
85
86 =head1 SUPPORT
87
88 You can find documentation for this module with the perldoc command.
89
90     perldoc LaTeX::TikZ
91
92 =head1 COPYRIGHT & LICENSE
93
94 Copyright 2010 Vincent Pit, all rights reserved.
95
96 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
97
98 =cut
99
100 1; # End of LaTeX::TikZ::Set::Path