Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moo conversion #178

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ my %args = (
},

requires => {
'Types::Standard' => '0',
'Data::MessagePack' => '0.38',
'Encode' => '2.26',
'Mouse' => 'v2.5.0',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this prereq should also be changed (and also in cpanfile).

Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires 'Mouse', 'v2.5.0';
requires 'Data::MessagePack', '0.38';
requires 'parent', '0.221';
requires 'Scalar::Util', '1.14';
requires 'Types::Standard';

# fix local $SIG{__DIE__} + eval problems
requires 'Encode', '2.26';
Expand Down
4 changes: 2 additions & 2 deletions lib/Text/Xslate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ sub _compiler {
my $compiler = $self->{compiler};

if(!ref $compiler){
require Mouse;
Mouse::load_class($compiler);
require Class::Load;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add Class::Load::XS to the list of optional dependencies -- e.g. via Dist::Zilla::Plugin::DynamicPrereqs require('Class::Load::XS') if not want_pp() and can_xs(); (or the equivalent unrolled code) in Makefile.PL.

Class::Load::load_class($compiler);

my $input_layer = $self->input_layer;
$compiler = $compiler->new(
Expand Down
36 changes: 19 additions & 17 deletions lib/Text/Xslate/Compiler.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package Text::Xslate::Compiler;
use Mouse;
use Mouse::Util::TypeConstraints;
use Moo 2.000001;

use Scalar::Util ();
use Carp ();

use Types::Standard '-all';

use Text::Xslate::Parser;
use Text::Xslate::Util qw(
$DEBUG
Expand Down Expand Up @@ -126,68 +127,68 @@ my %builtin = (

has lvar_id => ( # local variable id
is => 'rw',
isa => 'Int',
isa => Int,

init_arg => undef,
);

has lvar => ( # local variable id table
is => 'rw',
isa => 'HashRef[Int]',
isa => HashRef[Int],

init_arg => undef,
);

has const => (
is => 'rw',
isa => 'ArrayRef',
isa => ArrayRef,

init_arg => undef,
);

has macro_table => (
is => 'rw',
isa => 'HashRef',
isa => HashRef,

predicate => 'has_macro_table',
init_arg => undef,
);

has engine => ( # Xslate engine
is => 'ro',
isa => 'Object',
isa => Object,
required => 0,
weak_ref => 1,
);

has dependencies => (
is => 'ro',
isa => 'ArrayRef',
isa => ArrayRef,
init_arg => undef,
);

has type => (
is => 'rw',
isa => enum([qw(html xml text)]),
isa => Enum[qw(html xml text)],
default => 'html',
);

has syntax => (
is => 'rw',

default => 'Kolon',
default => sub{'Kolon'},
);

has parser_option => (
is => 'rw',
isa => 'HashRef',
isa => HashRef,

default => sub { {} },
);

has parser => (
is => 'rw',
isa => 'Object', # Text::Xslate::Parser
isa => Object, # Text::Xslate::Parser

handles => [qw(define_function)],

Expand All @@ -204,11 +205,13 @@ has input_layer => (
sub _build_parser {
my($self) = @_;
my $syntax = $self->syntax;

if(ref($syntax)) {
return $syntax;
}
else {
my $parser_class = Mouse::Util::load_first_existing_class(
require Class::Load;
my $parser_class = Class::Load::load_first_existing_class(
"Text::Xslate::Syntax::" . $syntax,
$syntax,
);
Expand All @@ -227,7 +230,7 @@ has cascade => (

has [qw(header footer macro)] => (
is => 'rw',
isa => 'ArrayRef',
isa => ArrayRef,
);

has current_file => (
Expand All @@ -244,7 +247,7 @@ has file => (

has overridden_builtin => (
is => 'ro',
isa => 'HashRef',
isa => HashRef,

default => sub { +{} },
);
Expand Down Expand Up @@ -1594,8 +1597,7 @@ sub _error {
die $self->make_error($message, $self->file, $line);
}

no Mouse;
no Mouse::Util::TypeConstraints;
no Moo;

__PACKAGE__->meta->make_immutable;
__END__
Expand Down
4 changes: 2 additions & 2 deletions lib/Text/Xslate/PP/Opcode.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Text::Xslate::PP::Opcode;
use Mouse;
use Moo 2.000001;
extends qw(Text::Xslate::PP::State);

use version; our $VERSION = version->declare('v3.5.6');
Expand Down Expand Up @@ -635,7 +635,7 @@ sub proccall {
}
}

no Mouse;
no Moo;
__PACKAGE__->meta->make_immutable();
__END__

Expand Down
4 changes: 2 additions & 2 deletions lib/Text/Xslate/PP/State.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Text::Xslate::PP::State; # implement tx_state_t
use Mouse;
use Moo 2.000001;

use Text::Xslate::Util qw(neat p $DEBUG);
use Text::Xslate::PP;
Expand Down Expand Up @@ -234,7 +234,7 @@ sub bad_arg {
return $st->error($context, "Wrong number of arguments for %s", $name);
}

no Mouse;
no Moo;
__PACKAGE__->meta->make_immutable;
1;
__END__
Expand Down
17 changes: 10 additions & 7 deletions lib/Text/Xslate/PP/Type/Macro.pm
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
package Text::Xslate::PP::Type::Macro;
use Mouse;

use warnings FATAL => 'recursion';

use Moo 2.000001;
use MooX::Types::MooseLike::Base qw(:all);

use overload
'&{}' => \&as_code_ref,
fallback => 1,
;

has name => (
is => 'ro',
isa => 'Str',
isa => Str,

required => 1,
);

has addr => (
is => 'ro',
isa => 'Int',
isa => Int,

required => 1,
);

has nargs => (
is => 'rw',
isa => 'Int',
isa => Int,

default => 0,
);

has outer => (
is => 'rw',
isa => 'Int',
isa => Int,

default => 0,
);

has state => (
is => 'rw',
isa => 'Object',
isa => Object,

required => 1,
weak_ref => 1,
Expand All @@ -53,7 +56,7 @@ sub as_code_ref {
};
}

no Mouse;
no Moo;
__PACKAGE__->meta->make_immutable;
__END__

Expand Down
4 changes: 2 additions & 2 deletions lib/Text/Xslate/PP/Type/Pair.pm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package Text::Xslate::PP::Type::Pair;
use Mouse;
use Moo 2.000001;

has [qw(key value)] => (
is => 'rw',
required => 1,
);

no Mouse;
no Moo;
__PACKAGE__->meta->make_immutable();
__END__

Expand Down
Loading