WE_Content/PerlDD.pm

filter: Statementstmt 69.8% 44 / 63 Branchbran 57.6% 15 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 4 totaltotal 64.3% 65 / 101 CC 13 SCAR 18.8
CC
13
Cov
66%
parse
11.0
serialize
6.0
new
5.0
CRAP 6.6
« Tie/DBI_DBM.pm ↑ Summary WE_Frontend/TextLayouter.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: PerlDD.pm,v 1.7 2004/04/14 21:23:51 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2001 Online Office Berlin. All rights reserved.
8 # Copyright (C) 2002 Slaven Rezic.
9 # This is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License, see the file COPYING.
11  
12 #
13 # Mail: slaven@rezic.de
14 # WWW: http://we-framework.sourceforge.net
15 #
16  
17 package WE_Content::PerlDD;
18 2 ▶use base qw(WE_Content::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use vars qw($VERSION $consider_safe);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 $VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);
23  
24 2 ▶$consider_safe = 0 if !defined $consider_safe;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $WE_Content::PerlDD::consider_safe 2 0 2
25  
26 4 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod undocumented
27 4 my($class, %args) = @_;
28 4 my $self = {};
29 4 ▶ while(my($k,$v) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 4 4 8
30 4 ▶ die "Option does not start with a dash: $k" if $k !~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^-/ 0 4 4
31 4 $self->{ucfirst(substr($k,1))} = $v;
32 }
33 4 bless $self, $class;
34 4 ▶ if ($self->{File}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'File'}) { } 2 2 4
elsif ($self->{'String'}) { } 2 0 2
35 2 $self->parse(-file => $self->{File});
36 } elsif ($self->{String}) {
37 2 $self->parse(-string => $self->{String});
38 }
39 4 $self;
40 }
41  
42 4 ▶sub parse {
Subroutine parse: called CC=8 SCAR=24.0
Pod undocumented
43 4 my($self, %args) = @_;
44 4 my $buf = $self->get_string(%args);
45  
46 2 ▶ use vars qw($outdata $emptydata);
Subroutine BEGIN: called CC=1 SCAR=0.0
47 4 $outdata = $emptydata = undef;
48  
49 4 ▶ if ($consider_safe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WE_Content::PerlDD::consider_safe) { } 0 4 4
50 0 eval $buf;
51 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
52 0 my $line = 1;
53 0 warn join("\n", map { sprintf("%3d: %s", $line++, $_) } split /\n/, $buf);
54 0 die $@;
55 }
56 } else {
57 4 require Safe;
58 4 undef $WE_Content::PerlDD::Safe::outdata;
59 4 undef $WE_Content::PerlDD::Safe::emptydata;
60 4 my $s = Safe->new("WE_Content::PerlDD::Safe");
61 4 $s->reval($buf);
62 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
63 0 my $line = 1;
64 0 warn join("\n", map { sprintf("%3d: %s", $line++, $_) } split /\n/, $buf);
65 0 die $@;
66 }
67 4 ▶ if (defined $WE_Content::PerlDD::Safe::outdata) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $WE_Content::PerlDD::Safe::outdata) { } 2 2 4
elsif (defined $WE_Content::PerlDD::Safe::emptydata) { } 2 0 2
68 2 $outdata = $WE_Content::PerlDD::Safe::outdata;
69 } elsif (defined $WE_Content::PerlDD::Safe::emptydata) {
70 2 $emptydata = $WE_Content::PerlDD::Safe::emptydata;
71 }
72 }
73  
74 4 ▶ if (defined $outdata) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $WE_Content::PerlDD::outdata) { } 2 2 4
elsif (defined $WE_Content::PerlDD::emptydata) { } 2 0 2
75 2 $self->{Object} = $outdata;
76 2 $self->{Type} = 'content';
77 } elsif (defined $emptydata) {
78 2 $self->{Object} = eval $emptydata; # XXX should use Safe!
79 2 $self->{Type} = 'template';
80 } else {
81 0 die "No data found!";
82 }
83  
84 4 $self->{Object};
85 }
86  
87 0 ▶sub serialize {
Subroutine serialize: not called CC=2 SCAR=17.9
Pod undocumented
88 0 my $self = shift;
89 0 require Data::Dumper;
90 0 my $dd = Data::Dumper->new([$self->{Object}], ['outdata']);
91 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
92 0 $dd->Indent(0); # to prevent a memory leak in ActivePerl 5.6.1
93 } else {
94 0 $dd->Indent(1);
95 }
96 0 $dd->Dump;
97 }
98  
99 0 ▶sub ext { "pl" }
Subroutine ext: not called CC=1 SCAR=6.9
Pod undocumented
100  
101 2 1;
102  
103 __END__
« Tie/DBI_DBM.pm ↑ Summary WE_Frontend/TextLayouter.pm »