]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set.pm
This is 0.02
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set.pm
index d4f67b61764ff925b8085c66a456050761fd810c..47363a4866fef4cbcca1b5ab2cc4ad58394dcf05 100644 (file)
@@ -9,11 +9,11 @@ LaTeX::TikZ::Set - Base role for LaTeX::TikZ set objects.
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 use Scope::Guard ();
 
@@ -23,9 +23,13 @@ use LaTeX::TikZ::Tools;
 
 use Any::Moose 'Role';
 
-requires qw(
- draw
-);
+=head1 ATTRIBUTES
+
+=head2 C<mods>
+
+Returns the list of the L<LaTeX::TikZ::Mod> objects associated with the current set.
+
+=cut
 
 has '_mods' => (
  is       => 'ro',
@@ -37,6 +41,32 @@ has '_mods' => (
 
 sub mods { @{$_[0]->_mods} }
 
+=head1 METHODS
+
+This method is required by the interface :
+
+=over 4
+
+=item *
+
+C<draw $formatter>
+
+Returns an array reference of TikZ code lines required to effectively draw the current set object, formatted by the L<LaTeX::TikZ::Formatter> object C<$formatter>.
+
+=back
+
+=cut
+
+requires qw(
+ draw
+);
+
+=head2 C<mod @mods>
+
+Apply the given list of L<LaTeX::TikZ::Mod> objects to the current set.
+
+=cut
+
 my $ltm_tc  = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod');
 my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
 my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip');
@@ -56,8 +86,22 @@ sub mod {
  our %mods;
  our $last_mod = 0;
 
- sub mods_unique {
-  my ($set) = @_;
+ around 'draw' => sub {
+  my ($orig, $set, $tikz) = @_;
+
+  local $last_mod = $last_mod;
+
+  # Save a deep copy
+  my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods;
+  my $guard     = Scope::Guard->new(sub {
+   for (keys %mods) {
+    if (exists $saved_idx{$_}) {
+     $#{$mods{$_}} = $saved_idx{$_};
+    } else {
+     delete $mods{$_};
+    }
+   }
+  });
 
   my (@mods, $last_layer);
 MOD:
@@ -67,7 +111,7 @@ MOD:
    my $tag = $mod->tag;
    my $old = $mods{$tag} || [];
    for (@$old) {
-    next MOD if $_->[0]->cover($mod);
+    next MOD if $_->[0]->covers($mod);
    }
    push @{$mods{$tag}}, [ $mod, $last_mod++, $is_layer ];
    push @mods,          $mod;
@@ -84,28 +128,6 @@ MOD:
                    values %mods;
   }
 
-  return @mods;
- }
-
- around 'draw' => sub {
-  my ($orig, $set, $tikz) = @_;
-
-  local $last_mod = $last_mod;
-
-  # Save a deep copy
-  my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods;
-  my $guard     = Scope::Guard->new(sub {
-   for (keys %mods) {
-    if (exists $saved_idx{$_}) {
-     $#{$mods{$_}} = $saved_idx{$_};
-    } else {
-     delete $mods{$_};
-    }
-   }
-  });
-
-  my @mods = $set->mods_unique;
-
   my $body = $set->$orig($tikz);
 
   if (@mods) {
@@ -118,6 +140,13 @@ MOD:
  };
 }
 
+=head2 C<layer $layer>
+
+Puts the current set in the corresponding layer.
+This is a shortcut for C<< $set->mod(Tikz->layer($layer)) >>.
+
+=cut
+
 sub layer {
  return $_[0] unless @_ > 1;
 
@@ -129,6 +158,13 @@ sub layer {
  )
 }
 
+=head2 C<clip $path>
+
+Clips the current set by the path given by C<$path>.
+This is a shortcut for C<< $set->mod(Tikz->clip($path)) >>.
+
+=cut
+
 sub clip {
  return $_[0] unless @_ > 1;
 
@@ -139,6 +175,10 @@ sub clip {
  )
 }
 
+=head1 SEE ALSO
+
+L<LaTeX::TikZ>.
+
 =head1 AUTHOR
 
 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.