One should use ->register now. It has been made into a class method.
use Sub::Name ();
+use LaTeX::TikZ::Interface;
+
use LaTeX::TikZ::Tools;
use Any::Moose;
0.8 * $width * ($tikz->scale / 5);
}
-use LaTeX::TikZ::Interface formatter => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ formatter => sub {
+ shift;
- __PACKAGE__->new(@_);
-};
+ __PACKAGE__->new(@_);
+ },
+);
__PACKAGE__->meta->make_immutable;
use Sub::Name ();
+use LaTeX::TikZ::Interface;
+
use LaTeX::TikZ::Tools;
use Any::Moose 'Util' => [ 'does_role' ];
}, $class;
}
-use LaTeX::TikZ::Interface functor => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ functor => sub {
+ shift;
- __PACKAGE__->new(rules => \@_);
-};
+ __PACKAGE__->new(rules => \@_);
+ },
+);
=head1 AUTHOR
use Sub::Name ();
-sub import {
+sub register {
shift;
- register(@_);
-}
-
-sub register {
while (@_ >= 2) {
my ($name, $code) = splice @_, 0, 2;
use LaTeX::TikZ::Formatter;
use LaTeX::TikZ::Mod::Formatted;
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use LaTeX::TikZ::Tools;
)
}
-use LaTeX::TikZ::Interface clip => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ clip => sub {
+ shift;
- __PACKAGE__->new(clip => $_[0]);
-};
+ __PACKAGE__->new(clip => $_[0]);
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
our $VERSION = '0.01';
+use LaTeX::TikZ::Interface;
+
use Any::Moose;
with 'LaTeX::TikZ::Mod';
sub apply { 'color=' . $_[0]->color }
-use LaTeX::TikZ::Interface color => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ color => sub {
+ shift;
- __PACKAGE__->new(color => $_[0]);
-};
+ __PACKAGE__->new(color => $_[0]);
+ },
+);
__PACKAGE__->meta->make_immutable;
our $VERSION = '0.01';
+use LaTeX::TikZ::Interface;
+
use Any::Moose;
with 'LaTeX::TikZ::Mod';
sub apply { 'fill=' . $_[0]->color }
-use LaTeX::TikZ::Interface fill => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ fill => sub {
+ shift;
- __PACKAGE__->new(color => $_[0]);
-};
+ __PACKAGE__->new(color => $_[0]);
+ },
+);
__PACKAGE__->meta->make_immutable;
use LaTeX::TikZ::Mod::Formatted;
+use LaTeX::TikZ::Interface;
+
use Any::Moose;
use Any::Moose 'Util::TypeConstraints';
)
}
-use LaTeX::TikZ::Interface layer => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ layer => sub {
+ shift;
- my $name = shift;
- __PACKAGE__->new(name => $name, @_);
-};
+ my $name = shift;
+ __PACKAGE__->new(name => $name, @_);
+ },
+);
__PACKAGE__->meta->make_immutable(
inline_constructor => 0,
our $VERSION = '0.01';
+use LaTeX::TikZ::Interface;
+
use Any::Moose;
with 'LaTeX::TikZ::Mod';
sub apply { 'fill', 'pattern=' . $_[0]->name($_[1]) }
-use LaTeX::TikZ::Interface pattern => sub {
- my $class = shift;
-
- my %args = @_;
- if (exists $args{class}) {
- $class = delete $args{class};
- $class = __PACKAGE__ . '::' . $class unless $class =~ /::/;
- (my $pm = $class) =~ s{::}{/}g;
- $pm .= '.pm';
- require $pm;
- }
-
- $class->new(%args);
-};
+LaTeX::TikZ::Interface->register(
+ pattern => sub {
+ my $class = shift;
+
+ my %args = @_;
+ if (exists $args{class}) {
+ $class = delete $args{class};
+ $class = __PACKAGE__ . '::' . $class unless $class =~ /::/;
+ (my $pm = $class) =~ s{::}{/}g;
+ $pm .= '.pm';
+ require $pm;
+ }
+
+ $class->new(%args);
+ },
+);
__PACKAGE__->meta->make_immutable;
our $VERSION = '0.01';
+use LaTeX::TikZ::Interface;
+
use Any::Moose;
with 'LaTeX::TikZ::Mod';
sub apply { $_[0]->content }
-use LaTeX::TikZ::Interface raw_mod => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ raw_mod => sub {
+ shift;
- __PACKAGE__->new(content => $_[0]);
-};
+ __PACKAGE__->new(content => $_[0]);
+ },
+);
__PACKAGE__->meta->make_immutable;
our $VERSION = '0.01';
+use LaTeX::TikZ::Interface;
+
use LaTeX::TikZ::Tools;
use Any::Moose;
sub apply { sprintf 'line width=%0.1fpt', $_[1]->thickness($_[0]->width) }
-use LaTeX::TikZ::Interface width => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ width => sub {
+ shift;
- __PACKAGE__->new(width => $_[0]);
-};
+ __PACKAGE__->new(width => $_[0]);
+ },
+);
__PACKAGE__->meta->make_immutable;
use LaTeX::TikZ::Set::Circle;
use LaTeX::TikZ::Set::Polyline;
+use LaTeX::TikZ::Interface;
+
use LaTeX::TikZ::Tools;
use Any::Moose 'Util::TypeConstraints' => [ 'find_type_constraint' ];
my $ltp_tc = find_type_constraint('LaTeX::TikZ::Point::Autocoerce');
-use LaTeX::TikZ::Interface arc => sub {
- shift;
- Carp::confess('Tikz->arc($first_point, $second_point, $center)') if @_ < 3;
- my ($a, $b, $c) = @_;
+LaTeX::TikZ::Interface->register(
+ arc => sub {
+ shift;
+ Carp::confess('Tikz->arc($first_point, $second_point, $center)') if @_ < 3;
+ my ($a, $b, $c) = @_;
- for ($a, $b, $c) {
- my $p = $ltp_tc->coerce($_);
- $ltp_tc->assert_valid($p);
- $_ = Math::Complex->make($p->x, $p->y);
- }
+ for ($a, $b, $c) {
+ my $p = $ltp_tc->coerce($_);
+ $ltp_tc->assert_valid($p);
+ $_ = Math::Complex->make($p->x, $p->y);
+ }
- my $r = abs($a - $c);
- Carp::confess("The two first points aren't on a circle of center the last")
+ my $r = abs($a - $c);
+ Carp::confess("The two first points aren't on a circle of center the last")
unless LaTeX::TikZ::Tools::numeq(abs($b - $c), $r);
- my $set = LaTeX::TikZ::Set::Circle->new(
- center => $c,
- radius => $r,
- );
-
- my $factor = 1/32;
-
- my $theta = (($b - $c) / ($a - $c))->arg;
- my $points = int(abs($theta) / abs(Math::Trig::acos(0.95)));
- $theta /= $points + 1;
- my $rho = (1 / cos($theta)) / (1 - $factor);
-
- my $ua = ($a - $c) * (1 - $factor) + $c;
- my $ub = ($b - $c) * (1 - $factor) + $c;
-
- my @outside = map { $_ * $rho + $c } (
- $a - $c,
- (map { ($a - $c) * Math::Complex->emake(1, $_ * $theta) } 1 .. $points),
- $b - $c,
- );
-
- $set->clip(
- LaTeX::TikZ::Set::Polyline->new(
- points => [ $ua, @outside, $ub ],
- closed => 1,
- ),
- );
-};
+ my $set = LaTeX::TikZ::Set::Circle->new(
+ center => $c,
+ radius => $r,
+ );
+
+ my $factor = 1/32;
+
+ my $theta = (($b - $c) / ($a - $c))->arg;
+ my $points = int(abs($theta) / abs(Math::Trig::acos(0.95)));
+ $theta /= $points + 1;
+ my $rho = (1 / cos($theta)) / (1 - $factor);
+
+ my $ua = ($a - $c) * (1 - $factor) + $c;
+ my $ub = ($b - $c) * (1 - $factor) + $c;
+
+ my @outside = map { $_ * $rho + $c } (
+ $a - $c,
+ (map { ($a - $c) * Math::Complex->emake(1, $_ * $theta) } 1 .. $points),
+ $b - $c,
+ );
+
+ $set->clip(
+ LaTeX::TikZ::Set::Polyline->new(
+ points => [ $ua, @outside, $ub ],
+ closed => 1,
+ ),
+ );
+ },
+);
=head1 AUTHOR
use LaTeX::TikZ::Set::Line;
+use LaTeX::TikZ::Interface;
+
use Any::Moose 'Util::TypeConstraints' => [ 'find_type_constraint' ];
my $ltp_tc = find_type_constraint('LaTeX::TikZ::Point::Autocoerce');
-use LaTeX::TikZ::Interface arrow => sub {
- shift;
-
- Carp::confess('Not enough arguments') unless @_ >= 2;
-
- my $from = $ltp_tc->coerce(shift);
-
- my $to;
- if ($_[0] eq 'dir') {
- my $dir = $ltp_tc->coerce($_[1]);
- $to = LaTeX::TikZ::Point->new(
- x => $from->x + $dir->x,
- y => $from->y + $dir->y,
- );
- } else {
- $to = $_[0];
- }
-
- LaTeX::TikZ::Set::Line->new(
- from => $from,
- to => $to,
- )->mod('->');
-};
+LaTeX::TikZ::Interface->register(
+ arrow => sub {
+ shift;
+
+ Carp::confess('Not enough arguments') unless @_ >= 2;
+
+ my $from = $ltp_tc->coerce(shift);
+
+ my $to;
+ if ($_[0] eq 'dir') {
+ my $dir = $ltp_tc->coerce($_[1]);
+ $to = LaTeX::TikZ::Point->new(
+ x => $from->x + $dir->x,
+ y => $from->y + $dir->y,
+ );
+ } else {
+ $to = $_[0];
+ }
+
+ LaTeX::TikZ::Set::Line->new(
+ from => $from,
+ to => $to,
+ )->mod('->');
+ },
+);
=head1 AUTHOR
use LaTeX::TikZ::Set::Point;
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use LaTeX::TikZ::Tools;
$set->center->path(@_) . ' circle (' . $tikz->len($set->radius) . ')';
}
-use LaTeX::TikZ::Interface circle => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ circle => sub {
+ shift;
- __PACKAGE__->new(center => $_[0], radius => $_[1]);
-};
+ __PACKAGE__->new(center => $_[0], radius => $_[1]);
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
use LaTeX::TikZ::Set::Point;
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use Any::Moose;
$set->from->path(@_) . ' -- ' . $set->to->path(@_);
}
-use LaTeX::TikZ::Interface line => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ line => sub {
+ shift;
- __PACKAGE__->new(from => $_[0], to => $_[1]);
-};
+ __PACKAGE__->new(from => $_[0], to => $_[1]);
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
our $VERSION = '0.01';
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use Any::Moose;
join ' ', map $_->path(@_), $set->ops;
}
-use LaTeX::TikZ::Interface path => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ path => sub {
+ shift;
- __PACKAGE__->new(ops => \@_);
-};
+ __PACKAGE__->new(ops => \@_);
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
use LaTeX::TikZ::Point;
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use Any::Moose;
'(' . $tikz->len($p->x) . ',' . $tikz->len($p->y) . ')';
}
-use LaTeX::TikZ::Interface point => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ point => sub {
+ shift;
- my $point = @_ == 0 ? 0
- : @_ == 1 ? $_[0]
- : \@_;
- __PACKAGE__->new(point => $point);
-};
+ my $point = @_ == 0 ? 0
+ : @_ == 1 ? $_[0]
+ : \@_;
+ __PACKAGE__->new(point => $point);
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
use LaTeX::TikZ::Set::Point;
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use Any::Moose;
($set->closed ? 'cycle' : ());
}
-use LaTeX::TikZ::Interface polyline => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ polyline => sub {
+ shift;
- __PACKAGE__->new(points => \@_);
-};
+ __PACKAGE__->new(points => \@_);
+ },
+ closed_polyline => sub {
+ shift;
-use LaTeX::TikZ::Interface closed_polyline => sub {
- shift;
-
- __PACKAGE__->new(points => \@_, closed => 1);
-};
+ __PACKAGE__->new(points => \@_, closed => 1);
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
our $VERSION = '0.01';
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use Any::Moose;
sub path { $_[0]->content }
-use LaTeX::TikZ::Interface raw => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ raw => sub {
+ shift;
- __PACKAGE__->new(content => join ' ', @_);
-};
+ __PACKAGE__->new(content => join ' ', @_);
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
use LaTeX::TikZ::Set::Point;
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use Any::Moose;
$class->$orig(@_);
};
-use LaTeX::TikZ::Interface rectangle => sub {
- shift;
- my ($p, $q) = @_;
+LaTeX::TikZ::Interface->register(
+ rectangle => sub {
+ shift;
+ my ($p, $q) = @_;
- my $is_relative = !blessed($q) && ref($q) eq 'HASH';
+ my $is_relative = !blessed($q) && ref($q) eq 'HASH';
- __PACKAGE__->new(
- from => $p,
- ($is_relative ? (map +($_ => $q->{$_}), qw/width height/) : (to => $q)),
- );
-};
+ __PACKAGE__->new(
+ from => $p,
+ ($is_relative ? (map +($_ => $q->{$_}), qw/width height/) : (to => $q)),
+ );
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
use LaTeX::TikZ::Scope;
+use LaTeX::TikZ::Interface;
use LaTeX::TikZ::Functor;
use Any::Moose;
$set->kids;
}
-use LaTeX::TikZ::Interface seq => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ seq => sub {
+ shift;
- __PACKAGE__->new(kids => \@_);
-};
+ __PACKAGE__->new(kids => \@_);
+ },
+);
LaTeX::TikZ::Functor->default_rule(
(__PACKAGE__) => sub {
for my $name (undef, ':)') {
eval {
- LaTeX::TikZ::Interface->import(
+ LaTeX::TikZ::Interface->register(
$name => sub { },
);
};
}
eval {
- LaTeX::TikZ::Interface->import(
+ LaTeX::TikZ::Interface->register(
'raw' => sub { },
);
};
for my $code (undef, [ ]) {
eval {
- LaTeX::TikZ::Interface->import(
+ LaTeX::TikZ::Interface->register(
'foo' => $code,
);
};
}
eval {
- LaTeX::TikZ::Interface->import(
+ LaTeX::TikZ::Interface->register(
'foo' => sub { @_ },
);
};
is_deeply [ Tikz->foo('hello') ], [ Tikz, 'hello' ], 'Tikz->foo works';
eval {
- LaTeX::TikZ::Interface->import(
+ LaTeX::TikZ::Interface->register(
'bar' => sub { @_ },
'baz' => undef,
);