From: Vincent Pit Date: Thu, 14 Apr 2011 17:36:17 +0000 (+0200) Subject: Flatten scopes at creation time X-Git-Tag: rt87282~8 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=commitdiff_plain;h=a27d2f20c230552d8207b08c13d6d7f73408261b Flatten scopes at creation time This simplifies the folding logic and allows us to get rid of flatten(). --- diff --git a/lib/LaTeX/TikZ/Scope.pm b/lib/LaTeX/TikZ/Scope.pm index 1a57c61..2222349 100644 --- a/lib/LaTeX/TikZ/Scope.pm +++ b/lib/LaTeX/TikZ/Scope.pm @@ -49,7 +49,7 @@ has '_mods_cache' => ( has 'body' => ( is => 'ro', - isa => 'LaTeX::TikZ::Scope|ArrayRef[Str]', + isa => 'ArrayRef[Str]', required => 1, init_arg => 'body', ); @@ -69,6 +69,14 @@ around 'BUILDARGS' => sub { } } + my $body = $args{body}; + if ($my_tc->check($body)) { + push @$mods, $body->mods; + $args{body} = $body->body; + } + + $args{mods} = $mods; + $class->$orig(%args); }; @@ -89,23 +97,8 @@ sub BUILD { =head1 METHODS -=head2 C - =cut -sub flatten { - my ($scope) = @_; - - do { - my $body = $scope->body; - return $scope unless $my_tc->check($body); - $scope = $scope->new( - mods => [ $scope->mods, $body->mods ], - body => $body->body, - ); - } while (1); -} - my $inter = Sub::Name::subname('inter' => sub { my ($lh, $rh) = @_; @@ -135,8 +128,6 @@ my $inter = Sub::Name::subname('inter' => sub { sub instantiate { my ($scope) = @_; - $scope = $scope->flatten; - my ($layer, @clips, @raw_mods); for ($scope->mods) { my $type = $_->type; @@ -192,10 +183,8 @@ sub fold { my (@left, @right); if ($my_tc->check($left)) { - $left = $left->flatten; if ($my_tc->check($right)) { - $right = $right->flatten; my ($only_left, $common, $only_right) = $inter->( $left->_mods_cache,