File Coverage

blib/lib/SVG/Convert/Driver/XAML.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package SVG::Convert::Driver::XAML;
2              
3 1     1   6 use strict;
  1         2  
  1         37  
4 1     1   5 use warnings;
  1         2  
  1         35  
5              
6 1     1   43 use base qw(SVG::Convert::BaseDriver);
  1         2  
  1         1270  
7              
8             __PACKAGE__->mk_accessors(qw/stylesheet/);
9              
10             use Carp::Clan;
11             use Path::Class qw(file);
12             use XML::LibXML;
13             use XML::LibXSLT;
14              
15             our $STYLE_FILE = file(__FILE__)->dir->file('XAML', 'svg2xaml.xsl')->stringify;
16              
17             =head1 NAME
18              
19             SVG::Convert::Driver::XAML - SVG::Convert XAML driver.
20              
21             =head1 VERSION
22              
23             version 0.02
24              
25             =cut
26              
27             our $VERSION = '0.02';
28              
29             =head1 SYNOPSIS
30              
31             =head1 METHODS
32              
33             =head2 new($args)
34              
35             =cut
36              
37             sub new {
38             my ($class, $args) = @_;
39              
40             my $self = $class->SUPER::new($args);
41             my $xslt = XML::LibXSLT->new;
42             my $stylesheet = $xslt->parse_stylesheet_file($STYLE_FILE);
43              
44             $self->stylesheet($stylesheet);
45              
46             return $self;
47             }
48              
49             =head2 convert_string($src_doc, $convert_opts)
50              
51             Convert to string.
52              
53             =cut
54              
55             sub convert_string {
56             my ($self, $src_doc, $convert_opts) = @_;
57              
58             return $self->_convert($src_doc, $convert_opts);
59             }
60              
61             =head2 convert_doc($src_doc, $convert_opts)
62              
63             Convert to L object.
64              
65             =cut
66              
67             sub convert_doc {
68             my ($self, $src_doc, $convert_opts) = @_;
69              
70             return $self->parser->parse_string(
71             $self->convert_string($src_doc, $convert_opts)
72             );
73             }
74              
75             =head2 convert_file($src_doc, $out_file, $convert_opts)
76              
77             Convert to file.
78              
79             =cut
80              
81             sub convert_file {
82             my ($self, $src_doc, $out_file, $convert_opts) = @_;
83             return $self->convert_doc($src_doc)->toFile($out_file);
84             }
85              
86             ###
87             ### protected methods
88             ###
89              
90             sub _convert {
91             my ($self, $src_doc, $convert_opts) = @_;
92              
93             my $result;
94             eval { $result = $self->stylesheet->transform($src_doc); };
95             if ($@) { croak($@); }
96              
97             my $xaml_str = $self->stylesheet->output_string($result);
98             $xaml_str =~ s/ /\n/g;
99              
100             return $xaml_str;
101             }
102              
103             =head1 AUTHOR
104              
105             Toru Yamaguchi, C<< >>
106              
107             =head1 BUGS
108              
109             Please report any bugs or feature requests to
110             C, or through the web interface at
111             L. I will be notified, and then you'll automatically be
112             notified of progress on your bug as I make changes.
113              
114             =head1 COPYRIGHT & LICENSE
115              
116             Copyright 2007 Toru Yamaguchi, All Rights Reserved.
117              
118             This program is free software; you can redistribute it and/or modify it
119             under the same terms as Perl itself.
120              
121             =cut
122              
123             1; # End of SVG::Convert::Driver::XAML