XML-LibXSLT
view release on metacpan or search on metacpan
lib/XML/LibXSLT/Quick.pm view on Meta::CPAN
package XML::LibXSLT::Quick;
use strict;
use warnings;
use 5.010;
use autodie;
use Carp ();
use XML::LibXML ();
use XML::LibXSLT ();
use vars qw( $VERSION );
$VERSION = '2.003000';
sub stylesheet
{
my $self = shift;
if (@_)
{
$self->{stylesheet} = shift;
}
return $self->{stylesheet};
}
sub xml_parser
{
my $self = shift;
if (@_)
{
$self->{xml_parser} = shift;
}
return $self->{xml_parser};
}
sub new
{
my $class = shift;
my $args = shift;
my $xslt = ( $args->{xslt_parser} // XML::LibXSLT->new() );
my $xml_parser = ( $args->{xml_parser} // XML::LibXML->new() );
my $style_doc = $xml_parser->load_xml(
location => $args->{location},
no_cdata => ( $args->{no_cdata} // 0 ),
);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $obj = bless( +{}, $class );
$obj->{xml_parser} = $xml_parser;
$obj->{stylesheet} = $stylesheet;
return $obj;
}
sub _write_utf8_file
{
my ( $out_path, $contents ) = @_;
open my $out_fh, '>:encoding(utf8)', $out_path;
print {$out_fh} $contents;
close($out_fh);
return;
}
sub _write_raw_file
{
my ( $out_path, $contents ) = @_;
open my $out_fh, '>:raw', $out_path;
print {$out_fh} $contents;
close($out_fh);
return;
}
sub generic_transform
{
my $self = shift;
my ( $dest, $source, ) = @_;
my $xml_parser = $self->xml_parser();
my $stylesheet = $self->stylesheet();
my $ret;
my $params = {};
if ( ref($source) eq '' )
{
$source = $xml_parser->parse_string($source);
}
elsif ( ref($source) eq 'HASH' )
{
if ( my $p = $source->{'params'} )
{
$params = $p;
}
my $type = $source->{type};
if (0)
{
}
elsif ( $type eq "file" )
{
( run in 0.630 second using v1.01-cache-2.11-cpan-39bf76dae61 )