Permalink
Browse files

clean up the commands to extend XML::Toolkit::App

  • Loading branch information...
1 parent b1762c5 commit 493cca9ee3721c261001b24fa9ecb02ff432b953 @perigrin committed Dec 29, 2010
View
@@ -20,7 +20,7 @@ THIS VERSION BREAKS BACKWARDS COMPATIBILITY.
use XML::Toolkit::App;
my $loader = XML::Toolkit::App->new( xmlns => { '' => 'MyApp' } )->loader;
- $loader->parse_file( $$file );
+ $loader->parse_file( $file );
print join '', @{ $loader->render };
or
View
@@ -4,20 +4,16 @@ our $VERSION = '0.02';
use XML::Toolkit::Config::Container;
-has xmlns => (
- isa => 'HashRef',
- is => 'ro',
- lazy => 1,
- builder => 'default_xmlns',
-);
+with qw( XML::Toolkit::Builder::NamespaceRegistry );
-sub default_xmlns { { 'MyApp' => '', } }
+sub default_xmlns { { '' => 'MyApp', } }
-has config_container => (
- does => 'XML::Toolkit::Config',
- handles => 'XML::Toolkit::Config',
- lazy => 1,
- builder => '_build_config_container',
+has _config => (
+ does => 'XML::Toolkit::Config',
+ handles => 'XML::Toolkit::Config',
+ lazy => 1,
+ init_arg => 'config',
+ builder => '_build_config_container',
);
sub _build_config_container {
@@ -41,7 +37,7 @@ This documentation refers to version 0.02.
use XML::Toolkit::App;
my $loader = XML::Toolkit::App->new( xmlns => { '' => 'MyApp' } )->loader;
- $loader->parse_file( $$file );
+ $loader->parse_file( $file );
print join '', @{ $loader->render };
or
@@ -45,7 +45,6 @@ after 'end_document' => sub {
sub get_class_name {
my ( $self, $el ) = @_;
-
# Get values for element
my $xmlns = $el->{'NamespaceURI'};
my $namespace = $self->namespace_map->{$xmlns};
@@ -55,8 +54,8 @@ sub get_class_name {
$self->unresolved_namespace_map->{$xmlns} = 1;
# Let's just return the local part here, even though it's wrong
- warn $self->xmlns->{''} . '::' . ucfirst $el->{'LocalName'};
- return $self->xmlns->{''} . '::' . ucfirst $el->{'LocalName'};
+ warn $self->get_xmlns('') . '::' . ucfirst $el->{'LocalName'};
+ return $self->get_xmlns('') . '::' . ucfirst $el->{'LocalName'};
}
# Construct class name
@@ -2,16 +2,15 @@ package XML::Toolkit::Cmd::Command::generate;
use Moose;
use namespace::autoclean;
-extends qw(MooseX::App::Cmd::Command);
+extends qw(MooseX::App::Cmd::Command XML::Toolkit::App);
use XML::Toolkit::Config::Container;
use MooseX::Types::Path::Class qw(File);
use Moose::Util::TypeConstraints;
-with qw(MooseX::Getopt::Dashes);
with qw(
+ MooseX::Getopt::Dashes
XML::Toolkit::Cmd::ClassTemplate
- XML::Toolkit::Builder::NamespaceRegistry
);
has input => (
@@ -42,9 +41,9 @@ END_TEMPLATE
sub run {
my ($self) = @_;
my $builder = XML::Toolkit::Config::Container->new(
- namespace => $self->namespace,
- namespace_map => $self->xmlns,
- template => $self->template,
+ namespace => $self->namespace,
+ xmlns => $self->xmlns,
+ template => $self->template,
)->builder;
$builder->parse_file( $self->input->stringify );
@@ -6,8 +6,11 @@ use aliased 'XML::Toolkit::Config::Container' => 'XMLTK::App';
use MooseX::Types::Path::Class qw(File);
use Moose::Util::TypeConstraints;
-extends qw(MooseX::App::Cmd::Command);
-with qw(MooseX::Getopt::Dashes);
+extends qw(MooseX::App::Cmd::Command XML::Toolkit::App);
+
+with qw(
+ MooseX::Getopt::Dashes
+);
has input => (
isa => File,
@@ -24,20 +27,13 @@ has namespace => (
sub _build_namespace { 'MyApp' }
-has _loader => (
- isa => 'XML::Toolkit::Loader',
- reader => 'loader',
- lazy_build => 1,
-);
-
-sub _build__loader {
- XMLTK::App->new( namespace => $_[0]->namespace )->loader;
-}
-
sub run {
my ($self) = @_;
- $self->loader->parse_file( $self->input->stringify );
- print join '', @{ $self->loader->render };
+ my $loader = $self->loader;
+ $loader->parse_file( $self->input->stringify );
+ my $generator = $self->generator;
+ $generator->render_object($loader->root_object);
+ print $generator->output;
}
__PACKAGE__->meta->make_immutable;
@@ -42,7 +42,7 @@ XML::Toolkit::Loader - A set of tools for Loading XML into Moose Objects
use XML::Toolkit::Loader;
my $loader = XML::Toolkit::Loader->new( namespace => 'MyApp' );
- $loader->parse_file( $$file );
+ $loader->parse_file( $file );
print join '', @{ $loader->render };
=head1 ATTRIBUTES

0 comments on commit 493cca9

Please sign in to comment.