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