]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Scope.pm
Simplify the layer application logic
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Scope.pm
index c048a1c700fdbd9bcba99b84d990d30f84d54b1a..d8ce86183abfde264ab100125983fc7873a3b34e 100644 (file)
@@ -9,11 +9,11 @@ LaTeX::TikZ::Scope - An object modeling a TikZ scope or layer.
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 use Sub::Name ();
 
@@ -21,6 +21,12 @@ use LaTeX::TikZ::Tools;
 
 use Any::Moose;
 
+=head1 ATTRIBUTES
+
+=head2 C<mods>
+
+=cut
+
 has '_mods' => (
  is       => 'ro',
  isa      => 'Maybe[ArrayRef[LaTeX::TikZ::Mod::Formatted]]',
@@ -37,6 +43,10 @@ has '_mods_cache' => (
  default  => sub { +{ } },
 );
 
+=head2 C<body>
+
+=cut
+
 has '_body' => (
  is       => 'rw',
  isa      => 'LaTeX::TikZ::Scope|ArrayRef[Str]',
@@ -48,13 +58,20 @@ my $ltmf_tc  = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Formatted'
 my $_body_tc = __PACKAGE__->meta->find_attribute_by_name('_body')
                                 ->type_constraint;
 
+=head1 METHODS
+
+=head2 C<mod>
+
+=cut
+
 sub mod {
  my $scope = shift;
 
  my $cache = $scope->_mods_cache;
 
  for (@_) {
-  my $mod = $ltmf_tc->check($_) ? $_ : $ltmf_tc->coerce($_);
+  my $mod = $ltmf_tc->coerce($_);
+  $ltmf_tc->assert_valid($mod);
   my $tag = $mod->tag;
   next if exists $cache->{$tag};
   $cache->{$tag} = $mod;
@@ -64,6 +81,10 @@ sub mod {
  $scope;
 }
 
+=head2 C<body>
+
+=cut
+
 sub body {
  my $scope = shift;
 
@@ -79,6 +100,10 @@ use overload (
  '@{}' => 'dereference',
 );
 
+=head2 C<flatten>
+
+=cut
+
 sub flatten {
  my ($scope) = @_;
 
@@ -113,6 +138,10 @@ my $inter = Sub::Name::subname('inter' => sub {
  return \@left, \@common, \@right;
 });
 
+=head2 C<instantiate>
+
+=cut
+
 sub instantiate {
  my ($scope) = @_;
 
@@ -163,8 +192,16 @@ sub instantiate {
  return @body;
 }
 
+=head2 C<dereference>
+
+=cut
+
 sub dereference { [ $_[0]->instantiate ] }
 
+=head2 C<fold>
+
+=cut
+
 sub fold {
  my ($left, $right, $rev) = @_;
 
@@ -182,20 +219,12 @@ sub fold {
    );
 
    my $has_different_layers;
-   for (@$only_left) {
+   for (@$only_left, @$only_right) {
     if ($_->type eq 'layer') {
      $has_different_layers = 1;
      last;
     }
    }
-   unless ($has_different_layers) {
-    for (@$only_right) {
-     if ($_->type eq 'layer') {
-      $has_different_layers = 1;
-      last;
-     }
-    }
-   }
 
    if (!$has_different_layers and @$common) {
     my $x = $left->new
@@ -231,6 +260,10 @@ sub fold {
 
 __PACKAGE__->meta->make_immutable;
 
+=head1 SEE ALSO
+
+L<LaTeX::TikZ>.
+
 =head1 AUTHOR
 
 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.