summaryrefslogtreecommitdiff
path: root/lib/Tree
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Tree')
-rw-r--r--lib/Tree/Transform/XSLTish.pm7
-rw-r--r--lib/Tree/Transform/XSLTish/Context.pm2
-rw-r--r--lib/Tree/Transform/XSLTish/Transformer.pm21
-rw-r--r--lib/Tree/Transform/XSLTish/Utils.pm6
4 files changed, 20 insertions, 16 deletions
diff --git a/lib/Tree/Transform/XSLTish.pm b/lib/Tree/Transform/XSLTish.pm
index 4c29afa..42b7222 100644
--- a/lib/Tree/Transform/XSLTish.pm
+++ b/lib/Tree/Transform/XSLTish.pm
@@ -12,7 +12,8 @@ our $VERSION='0.1';
my @DEFAULT_EXPORTS=('tree_rule',
'default_rules',
- 'new_transformer' => {-as => 'new'});
+ 'new_transformer' => {-as => 'new'},
+ );
Sub::Exporter::setup_exporter({
exports => [qw(tree_rule default_rules new_transformer engine_class engine_factory)],
@@ -81,12 +82,10 @@ sub engine_factory(&) {
return;
}
-sub _transformer_class { 'Tree::Transform::XSLTish::Transformer' };
-
sub new_transformer {
my $rules_package=shift;
- return _transformer_class->new(rules_package=>$rules_package,@_);
+ return Tree::Transform::XSLTish::Transformer->new(rules_package=>$rules_package,@_);
}
1;
diff --git a/lib/Tree/Transform/XSLTish/Context.pm b/lib/Tree/Transform/XSLTish/Context.pm
index 0890401..96670ec 100644
--- a/lib/Tree/Transform/XSLTish/Context.pm
+++ b/lib/Tree/Transform/XSLTish/Context.pm
@@ -2,6 +2,8 @@ package Tree::Transform::XSLTish::Context;
use Moose;
use Carp::Clan qw(^Tree::Transform::XSLTish);
+our $VERSION='0.1';
+
has 'current_node' => ( is => 'rw', isa => 'Object' );
has 'node_list' => ( is => 'rw', isa => 'ArrayRef[Object]' );
diff --git a/lib/Tree/Transform/XSLTish/Transformer.pm b/lib/Tree/Transform/XSLTish/Transformer.pm
index 857143a..0d241e4 100644
--- a/lib/Tree/Transform/XSLTish/Transformer.pm
+++ b/lib/Tree/Transform/XSLTish/Transformer.pm
@@ -8,14 +8,12 @@ use Tree::Transform::XSLTish::Context;
use Tree::XPathEngine;
use Carp::Clan qw(^Tree::Transform::XSLTish);
+our $VERSION='0.1';
+
subtype 'Tree::Transform::XSLTish::Engine'
=> as 'Object'
=> where {
- my $object=$_;
- for my $meth (qw(findnodes)) {
- return unless $object->can($meth);
- }
- return 1;
+ return $_->can('findnodes') ? 1 : ();
};
has 'rules_package' => (is => 'ro', isa => 'ClassName');
@@ -52,7 +50,7 @@ sub _build_engine {
return Tree::XPathEngine->new();
}
-sub it { $_[0]->context->current_node }
+sub it { return $_[0]->context->current_node }
sub transform {
my ($self,$tree)=@_;
@@ -115,7 +113,7 @@ sub find_rule {
return $ret if $ret;
}
- croak "No valid rule";
+ croak 'No valid rule';
}
sub find_rule_by_name {
@@ -140,12 +138,12 @@ sub find_rule_in_package {
my $rules=$store->{by_match};
my @candidates=
- sort { $b->{priority} <=> $a->{priority} }
- grep { $self->rule_matches($_) } @$rules;
+ sort { $b->{priority} <=> $a->{priority} } ## no critic (ProhibitReverseSortBlock)
+ grep { $self->rule_matches($_) } @{$rules};
if (@candidates > 1 and
$candidates[0]->{priority} ==
$candidates[1]->{priority}) {
- croak "Ambiguous rule application";
+ croak 'Ambiguous rule application';
}
elsif (@candidates >= 1) {
return $candidates[0];
@@ -202,7 +200,7 @@ sub rule_matches {
__PACKAGE__->meta->make_immutable;no Moose;
-package Tree::Transform::XSLTish::ContextGuard;
+package Tree::Transform::XSLTish::ContextGuard; ## no critic (ProhibitMultiplePackages)
sub new {
my ($class,$trans,$context)=@_;
@@ -212,6 +210,7 @@ sub new {
sub DESTROY {
$_[0]->{trans}->leave();
+ return;
}
1;
diff --git a/lib/Tree/Transform/XSLTish/Utils.pm b/lib/Tree/Transform/XSLTish/Utils.pm
index 770426f..8546919 100644
--- a/lib/Tree/Transform/XSLTish/Utils.pm
+++ b/lib/Tree/Transform/XSLTish/Utils.pm
@@ -3,12 +3,14 @@ use strict;
use warnings;
use Class::MOP;
+our $VERSION='0.1';
+
my $RULES_NAME='%_tree_transform_rules';
sub _rules_store {
my $pack=Class::MOP::Class->initialize($_[0]);
- if (! $pack->has_package_symbol($RULES_NAME) ) {
+ if (! $pack->has_package_symbol($RULES_NAME) ) {
$pack->add_package_symbol($RULES_NAME,{});
}
return $pack->get_package_symbol($RULES_NAME);
@@ -22,6 +24,8 @@ sub _set_engine_factory {
my $pack=Class::MOP::Class->initialize($pack_name);
$pack->add_package_symbol($ENGINE_FACTORY_NAME_WITH_SIGIL,$factory);
+
+ return;
}