File Coverage

blib/lib/MojoX/Renderer/XSLT/XML/LibXSLT.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package MojoX::Renderer::XSLT::XML::LibXSLT;
2              
3 1     1   5917 use warnings;
  1         3  
  1         39  
4 1     1   7 use strict;
  1         2  
  1         38  
5              
6 1     1   6 use base 'Mojo::Base';
  1         2  
  1         1094  
7 1     1   17057 use XML::LibXML;
  0            
  0            
8             use XML::LibXSLT;
9              
10             =head1 NAME
11              
12             MojoX::Renderer::XSLT::XML::LibXSLT - The great new MojoX::Renderer::XSLT::XML::LibXSLT!
13              
14             =head1 VERSION
15              
16             Version 0.01
17              
18             =cut
19              
20             our $VERSION = '0.01';
21              
22              
23             =head1 SYNOPSIS
24              
25             Quick summary of what the module does.
26              
27             Perhaps a little code snippet.
28              
29             use MojoX::Renderer::XSLT::XML::LibXSLT;
30              
31             my $foo = MojoX::Renderer::XSLT::XML::LibXSLT->new();
32             ...
33              
34             =head1 EXPORT
35              
36             A list of functions that can be exported. You can delete this section
37             if you don't export anything, such as for a purely object-oriented module.
38              
39             =head1 FUNCTIONS
40              
41             =head2 new
42              
43             Constructor
44              
45             =cut
46              
47             sub new {
48             my $class = shift;
49             my $self = $class->SUPER::new();
50             $self->_init(@_);
51             return $self;
52             }
53              
54             sub _init {
55             my $self = shift;
56             my $params = shift;
57              
58             $self->{_xslt_processor} = XML::LibXSLT->new();
59             $self->{_xml_parser} = XML::LibXML->new();
60            
61             if($params) {
62             $self->{_xslt_processor}->max_depth($params->{max_depth}) if exists $params->{max_depth} && defined $params->{max_depth};
63            
64             $self->{_xslt_processor}->debug_callback($params->{debug_callback}) if exists $params->{debug_callback} && defined $params->{debug_callback};
65            
66             if(exists $params->{register_function} && ref($params->{register_function}) eq "ARRAY") {
67             foreach my $reg (@{ $params->{register_function} }) {
68             $self->{_xslt_processor}->register_function($reg->{urn},
69             $reg->{name},
70             $reg->{subref});
71             }
72             }
73             }
74             }
75              
76             =head3 transform
77              
78             Parse XML and stylesheet into XML::LibXML document objects. Do XSLT transform.
79              
80             =cut
81              
82             sub transform {
83             my $self = shift;
84             my ($stylesheet,$xml) = @_;
85              
86             return undef unless $stylesheet && $xml;
87              
88             my $xml_doc = $self->{_xml_parser}->parse_string($xml) or die "Failure to parse XML $xml $@";
89             my $style_doc = $self->{_xml_parser}->parse_file($stylesheet) or die "Failure to parse stylesheet $stylesheet $@";
90             my $parsed_stylesheet = $self->{_xslt_processor}->parse_stylesheet($style_doc) or die "Failure to parse style doc $@";
91             my $results = $parsed_stylesheet->transform($xml_doc) or die "Failure to do XSLT transform $@";
92             return $parsed_stylesheet->output_as_bytes($results);
93             }
94              
95             =head1 AUTHOR
96              
97             Bob Faist, C<< >>
98              
99             =head1 BUGS
100              
101             Please report any bugs or feature requests to C, or through
102             the web interface at L. I will be notified, and then you'll
103             automatically be notified of progress on your bug as I make changes.
104              
105              
106              
107              
108             =head1 SUPPORT
109              
110             You can find documentation for this module with the perldoc command.
111              
112             perldoc MojoX::Renderer::XSLT::XML::LibXSLT
113              
114              
115             You can also look for information at:
116              
117             =over 4
118              
119             =item * RT: CPAN's request tracker
120              
121             L
122              
123             =item * AnnoCPAN: Annotated CPAN documentation
124              
125             L
126              
127             =item * CPAN Ratings
128              
129             L
130              
131             =item * Search CPAN
132              
133             L
134              
135             =back
136              
137              
138             =head1 ACKNOWLEDGEMENTS
139              
140              
141             =head1 COPYRIGHT & LICENSE
142              
143             Copyright 2010 Bob Faist, all rights reserved.
144              
145             This program is free software; you can redistribute it and/or modify it
146             under the same terms as Perl itself.
147              
148              
149             =cut
150              
151             1; # End of MojoX::Renderer::XSLT::XML::LibXSLT