=cut
has '_mods' => (
- is => 'ro',
+ is => 'rw',
isa => 'Maybe[ArrayRef[LaTeX::TikZ::Mod::Formatted]]',
- init_arg => undef,
+ init_arg => 'mods',
default => sub { [ ] },
);
=cut
-has '_body' => (
- is => 'rw',
+has 'body' => (
+ is => 'ro',
isa => 'LaTeX::TikZ::Scope|ArrayRef[Str]',
+ required => 1,
init_arg => 'body',
);
-my $my_tc = LaTeX::TikZ::Tools::type_constraint(__PACKAGE__);
-my $ltmf_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Formatted');
-my $_body_tc = __PACKAGE__->meta->find_attribute_by_name('_body')
- ->type_constraint;
+my $my_tc = LaTeX::TikZ::Tools::type_constraint(__PACKAGE__);
+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
+around 'BUILDARGS' => sub {
+ my ($orig, $class, %args) = @_;
-=head2 C<mod>
+ my $mods = $args{mods};
+ if (defined $mods and ref $mods eq 'ARRAY') {
+ for my $mod (@$mods) {
+ $mod = $ltmf_tc->coerce($mod);
+ }
+ }
-=cut
+ $class->$orig(%args);
+};
-sub mod {
+sub BUILD {
my $scope = shift;
my $cache = $scope->_mods_cache;
- for (@_) {
- my $mod = $ltmf_tc->coerce($_);
- $ltmf_tc->assert_valid($mod);
+ my @unique_mods;
+ for my $mod ($scope->mods) {
my $tag = $mod->tag;
next if exists $cache->{$tag};
$cache->{$tag} = $mod;
- push @{$scope->_mods}, $mod;
- }
-
- $scope;
-}
-
-=head2 C<body>
-
-=cut
-
-sub body {
- my $scope = shift;
-
- if (@_) {
- $scope->_body($_[0]);
- $scope;
- } else {
- @{$scope->_body};
+ push @unique_mods, $mod;
}
+ $scope->_mods(\@unique_mods);
}
-use overload (
- '@{}' => 'dereference',
-);
+=head1 METHODS
=head2 C<flatten>
my ($scope) = @_;
do {
- my $body = $scope->_body;
+ my $body = $scope->body;
return $scope unless $my_tc->check($body);
- $scope = $scope->new
- ->mod ($scope->mods, $body->mods)
- ->body($body->_body)
+ $scope = $scope->new(
+ mods => [ $scope->mods, $body->mods ],
+ body => $body->body,
+ );
} while (1);
}
}
}
- my @body = $scope->body;
+ my @body = @{$scope->body};
my $mods_string = @raw_mods ? ' [' . join(',', @raw_mods) . ']' : undef;
return @body;
}
-=head2 C<dereference>
-
-=cut
-
-sub dereference { [ $_[0]->instantiate ] }
-
=head2 C<fold>
=cut
}
if (!$has_different_layers and @$common) {
- my $x = $left->new
- ->mod(@$only_left)
- ->body($left->_body);
- my $y = $left->new
- ->mod(@$only_right)
- ->body($right->_body);
- return $left->new
- ->mod(@$common)
- ->body(fold($x, $y, $rev));
+ my $x = $left->new(
+ mods => $only_left,
+ body => $left->body,
+ );
+ my $y = $left->new(
+ mods => $only_right,
+ body => $right->body,
+ );
+ return $left->new(
+ mods => $common,
+ body => fold($x, $y, $rev),
+ );
} else {
@right = $right->instantiate;
}
} else {
- $_body_tc->assert_valid($right);
+ $body_tc->assert_valid($right);
@right = @$right;
}
if ($my_tc->check($right)) {
return fold($right, $left, 1);
} else {
- $_body_tc->assert_valid($_) for $left, $right;
+ $body_tc->assert_valid($_) for $left, $right;
@left = @$left;
@right = @$right;
}
$rev ? [ @right, @left ] : [ @left, @right ];
}
+use overload (
+ '@{}' => sub { [ $_[0]->instantiate ] },
+);
+
__PACKAGE__->meta->make_immutable;
=head1 SEE ALSO
pod_coverage_ok( 'LaTeX::TikZ::Interface' );
pod_coverage_ok( 'LaTeX::TikZ' );
-pod_coverage_ok( 'LaTeX::TikZ::Context', $moose_private);
+pod_coverage_ok( 'LaTeX::TikZ::Context', $moose_private );
pod_coverage_ok( 'LaTeX::TikZ::Formatter' );
pod_coverage_ok( 'LaTeX::TikZ::Functor' );
pod_coverage_ok( 'LaTeX::TikZ::Functor::Rule' );
pod_coverage_ok( 'LaTeX::TikZ::Mod::Color' );
pod_coverage_ok( 'LaTeX::TikZ::Mod::Fill' );
pod_coverage_ok( 'LaTeX::TikZ::Mod::Formatted' );
-pod_coverage_ok( 'LaTeX::TikZ::Mod::Layer', $moose_private);
+pod_coverage_ok( 'LaTeX::TikZ::Mod::Layer', $moose_private );
pod_coverage_ok( 'LaTeX::TikZ::Mod::Pattern' );
pod_coverage_ok( 'LaTeX::TikZ::Mod::Pattern::Dots' );
pod_coverage_ok( 'LaTeX::TikZ::Mod::Pattern::Lines' );
pod_coverage_ok( 'LaTeX::TikZ::Mod::Width' );
pod_coverage_ok( 'LaTeX::TikZ::Point' );
pod_coverage_ok( 'LaTeX::TikZ::Point::Math::Complex' );
-pod_coverage_ok( 'LaTeX::TikZ::Scope' );
+pod_coverage_ok( 'LaTeX::TikZ::Scope', $moose_private );
pod_coverage_ok( 'LaTeX::TikZ::Set' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Arc' );
pod_coverage_ok( 'LaTeX::TikZ::Set::Arrow' );