WE_Content/YAML.pm

filter: Statementstmt 79.1% 38 / 48 Branchbran 50.0% 8 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 4 totaltotal 69.7% 53 / 76 CC 9 SCAR 14.9
CC
9
Cov
72%
parse
7.5
new
5.3
ext
2.0
CRAP 4.4
« WE_Frontend/Plugin/Navigation/Object.pm ↑ Summary WE_Frontend/Info.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: YAML.pm,v 1.7 2003/12/16 15:21:23 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2002 Slaven Rezic.
8 # This is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License, see the file COPYING.
10  
11 #
12 # Mail: slaven@rezic.de
13 # WWW: http://we-framework.sourceforge.net
14 #
15  
16 package WE_Content::YAML;
17 2 ▶use base qw(WE_Content::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 $VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);
22  
23 2 ▶use YAML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 YAML->VERSION(0.30); # YAML::Dump
25  
26 2 ▶sub new {
Subroutine new: called CC=5 SCAR=16.6
Pod undocumented
27 2 my($class, %args) = @_;
28 2 my $self = {};
29 2 ▶ while(my($k,$v) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 2 2 4
30 2 ▶ die "Option does not start with a dash: $k" if $k !~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^-/ 0 2 2
31 2 $self->{ucfirst(substr($k,1))} = $v;
32 }
33 2 bless $self, $class;
34 2 ▶ if ($self->{File}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'File'}) { } 0 2 2
elsif ($self->{'String'}) { } 2 0 2
35 0 $self->parse(-file => $self->{File});
36 } elsif ($self->{String}) {
37 2 $self->parse(-string => $self->{String});
38 }
39 2 $self;
40 }
41  
42 2 ▶sub parse {
Subroutine parse: called CC=5 SCAR=20.2
Pod undocumented
43 2 my($self, %args) = @_;
44 2 my $buf = $self->get_string(%args);
45  
46 2 my $emptydata;
47 2 my $outdata = eval { local $SIG{__DIE__}; YAML::Load($buf) };
48 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
49 0 my $line = 1;
50 0 warn join("\n", map { sprintf("%3d: %s", $line++, $_) } split /\n/, $buf);
51 0 die $@;
52 }
53 2 ▶ if (!defined $outdata) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $outdata) 0 2 2
54 0 die "Loading emptydata not yet supported...";
55 }
56  
57 2 ▶ if (defined $outdata) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $outdata) { } 2 0 2
elsif (defined $emptydata) { } 0 0 0
58 2 $self->{Object} = $outdata;
59 2 $self->{Type} = 'content';
60 } elsif (defined $emptydata) {
61 0 $self->{Object} = eval $emptydata; # XXX should use Safe!
62 0 $self->{Type} = 'template';
63 } else {
64 0 die "No data found!";
65 }
66  
67 2 $self->{Object};
68 }
69  
70 3 ▶sub serialize {
Subroutine serialize: called CC=1 SCAR=0.0
Pod undocumented
71 3 my $self = shift;
72 3 YAML::Dump($self->{Object});
73 }
74  
75 0 ▶sub ext { "yml" }
Subroutine ext: not called CC=1 SCAR=6.9
Pod undocumented
76  
77 2 1;
78  
79 __END__
« WE_Frontend/Plugin/Navigation/Object.pm ↑ Summary WE_Frontend/Info.pm »