]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Formatter.pm
Make sure POD headings are linkable
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Formatter.pm
index 368e0afea2475dc24b6c86dc636c9f0ee026c277..e06676affd631ee025852b30595eba295b8fee1c 100644 (file)
@@ -9,11 +9,11 @@ LaTeX::TikZ::Formatter - LaTeX::TikZ formatter object.
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 DESCRIPTION
 
@@ -29,8 +29,8 @@ use LaTeX::TikZ::Interface;
 
 use LaTeX::TikZ::Tools;
 
-use Any::Moose;
-use Any::Moose 'Util::TypeConstraints';
+use Mouse;
+use Mouse::Util::TypeConstraints;
 
 =head1 ATTRIBUTES
 
@@ -45,7 +45,7 @@ Defaults to C<cm>.
 
 has 'unit' => (
  is      => 'ro',
- isa     => enum([ qw/cm pt/ ]),
+ isa     => enum([ qw<cm pt> ]),
  default => 'cm',
 );
 
@@ -131,7 +131,7 @@ sub id {
 
  my $origin = $tikz->origin;
  if (defined $origin) {
-  my ($x, $y) = map $origin->$_, qw/x y/;
+  my ($x, $y) = map $origin->$_, qw<x y>;
   $origin = "($x;$y)";
  } else {
   $origin = "(0;0)";
@@ -139,10 +139,12 @@ sub id {
 
  join $;, map {
   defined() ? "$_" : '(undef)';
- } map($tikz->$_, qw/unit format scale width height/), $origin;
+ } map($tikz->$_, qw<unit format scale width height>), $origin;
 }
 
-=head2 C<render @sets>
+=head2 C<render>
+
+    my ($header_lines, $mod_lines, $content_lines) = $formatter->render(@sets);
 
 Processes all the L<LaTeX::TikZ::Set> objects given in C<@sets> to produce the actual TikZ code to insert in the LaTeX file.
 First, all the mods applied to the sets and their subsets are collected, and a declaration is emitted if needed for each of them by calling L<LaTeX::TikZ::Mod/declare>.
@@ -166,7 +168,28 @@ Finally, there's one array reference for each given TikZ set, which contain the
 
 =back
 
-    my ($header, $declarations, $seq1_body, $seq2_body) = $formatter->render($set1, $set2);
+The lines returned by L</render> don't end with a line feed.
+
+    my ($header, $declarations, $set1_body, $set2_body) = $formatter->render($set1, $set2);
+
+    open my $tex, '>', 'test.tex' or die "open('>test.tex'): $!";
+
+    print $tex "$_\n" for (
+     "\\documentclass[12pt]{article}",
+     @$header,
+     "\\begin{document}",
+      "\\pagestyle{empty}",
+      @$declarations,
+      "First set :"
+      "\\begin{center}",
+       @$set1_body,
+      "\\end{center}",
+      "Second set :"
+      "\\begin{center}",
+       @$set2_body,
+      "\\end{center}",
+     "\\end{document}",
+    );
 
 =cut
 
@@ -191,11 +214,9 @@ my $find_mods = do {
     }
    }
 
-   my @subsets = $set->isa('LaTeX::TikZ::Set::Sequence')
+   my @subsets = $set->does('LaTeX::TikZ::Set::Container')
                  ? $set->kids
-                 : $set->isa('LaTeX::TikZ::Set::Path')
-                   ? $set->ops
-                   : ();
+                 : ();
 
    $find_mods_rec->($_, $layers, $others) for @subsets;
   });
@@ -277,7 +298,9 @@ sub render {
  return \@header, \@decls, @bodies;
 }
 
-=head2 C<len $len>
+=head2 C<len>
+
+    my $physical_len = $formatter->len($logical_len);
 
 Format the given length according to the formatter options.
 
@@ -291,7 +314,9 @@ sub len {
  sprintf $tikz->format . $tikz->unit, $len * $tikz->scale;
 }
 
-=head2 C<angle $theta>
+=head2 C<angle>
+
+    my $physical_angle = $formatter->angle($logical_angle);
 
 Format the given angle (in radians) according to the formatter options.
 
@@ -307,7 +332,9 @@ sub angle {
  sprintf $tikz->format, POSIX::ceil($a);
 }
 
-=head2 C<label $name, $pos>
+=head2 C<label>
+
+    my $label = $formatter->label($name, $pos);
 
 Returns the TikZ code for a point labeled C<$name> at position C<$pos> according to the formatter options.
 
@@ -367,7 +394,7 @@ 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.