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