|
has 'text' => (
isa => 'Str' ,
is => 'rw' ,
required => 1,
default => '' ,
);
around BUILDARGS => sub {
my $orig = shift ;
my $class = shift ;
if ( @_ == 1 && ! ref $_ [0] ) {
return $class -> $orig ( text => $_ [0] );
}
else {
return $class -> $orig ( @_ );
}
};
has 'is_valid' => (
isa => 'Bool' ,
is => 'ro' ,
lazy => 1,
default => sub {
my $self = shift ;
return length $self ->text;
},
);
has 'as_xml_gen' => (
isa => 'Object' ,
is => 'ro' ,
lazy => 1,
builder => '_build_as_xml_gen' ,
);
sub _build_as_xml_gen {
my $self = shift ;
my $gen = XML::Generator->new( ':pretty' );
return $gen ->p(
\ $self ->text,
);
}
1;
|