use Any::Moose;
+=head1 ATTRIBUTES
+
+=head2 C<mods>
+
+=cut
+
has '_mods' => (
is => 'ro',
isa => 'Maybe[ArrayRef[LaTeX::TikZ::Mod::Formatted]]',
default => sub { +{ } },
);
+=head2 C<body>
+
+=cut
+
has '_body' => (
is => 'rw',
isa => 'LaTeX::TikZ::Scope|ArrayRef[Str]',
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;
$scope;
}
+=head2 C<body>
+
+=cut
+
sub body {
my $scope = shift;
'@{}' => 'dereference',
);
+=head2 C<flatten>
+
+=cut
+
sub flatten {
my ($scope) = @_;
return \@left, \@common, \@right;
});
+=head2 C<instantiate>
+
+=cut
+
sub instantiate {
my ($scope) = @_;
return @body;
}
+=head2 C<dereference>
+
+=cut
+
sub dereference { [ $_[0]->instantiate ] }
+=head2 C<fold>
+
+=cut
+
sub fold {
my ($left, $right, $rev) = @_;
$right->_mods_cache,
);
- if (@$common) {
+ my $has_different_layers;
+ for (@$only_left) {
+ 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
->mod(@$only_left)
->body($left->_body);