1. Shlomi Fish
  2. Fiction-XML

Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed b8c3696

Got rid of _init in ::FromProto - convert to Moose 'default'.

  • Participants
  • Parent commits 75dc1a9
  • Branches default

Comments (0)

Files changed (1)

File perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/Fiction/FromProto.pm

View file
 
 use Carp;
 
-use base 'XML::Grammar::Fiction::Base';
-
 use XML::Writer;
 use HTML::Entities ();
 
 
 use List::Util (qw(first));
 
-has "_parser" => ('isa' => "XML::Grammar::Fiction::FromProto::Parser", 'is' => "rw");
+has '_parser_class' =>
+(
+    is => "ro",
+    isa => "Str",
+    init_arg => "parser_class",
+    default => "XML::Grammar::Fiction::FromProto::Parser::QnD",
+);
+
+has "_parser" => (
+    'isa' => "XML::Grammar::Fiction::FromProto::Parser", 
+    'is' => "rw",
+    lazy => 1,
+    default => sub { 
+        my $self = shift; 
+        return $self->_parser_class->new();
+    },
+);
+
 has "_writer" => ('isa' => "XML::Writer", 'is' => "rw");
 
 my $fiction_ns = q{http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/fiction-xml-0.2/};
 
 =cut
 
-sub _init
-{
-    my ($self, $args) = @_;
-
-    local $Parse::RecDescent::skip = "";
-
-    my $parser_class = 
-        ($args->{parser_class} || "XML::Grammar::Fiction::FromProto::Parser::QnD");
-
-    $self->_parser(
-        $parser_class->new()
-    );
-
-    return 0;
-}
-
 =head2 $self->convert({ source => { file => $path_to_file } })
 
 Converts the file $path_to_file to XML and returns it. Throws an exception