Created
November 20, 2012 16:45
-
-
Save yanick/4119156 to your computer and use it in GitHub Desktop.
XML::Simple::SelfContained
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package XML::Writer::SelfContained; | |
=pod | |
Tired of giving a output to XML::Writer? Me too. This allows to do | |
use 5.10.0; | |
use XML::Writer::SelfContained; | |
my $doc = XML::Writer::SelfContained->new; | |
$doc->startTag('doc'); | |
$doc->characters("Howdie"); | |
$doc->dataElement( stuff => "Mooh" ); | |
$doc->endTag; | |
say $doc; | |
=cut | |
use strict; | |
use warnings; | |
use base 'XML::Writer'; | |
use overload '""' => \&to_string; | |
sub new { | |
my $output; | |
my $self = XML::Writer->new( OUTPUT => \$output, @_ ); | |
$self->{output_stream} = \$output; | |
return bless $self, 'XML::Writer::SelfContained'; | |
}; | |
sub to_string { | |
my $self = shift; | |
$self->end; | |
return ${$self->{output_stream}}; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WWW::BambooHR::XMLWriter ?
I don't have much XML simple experience, but this does look simple to use.