MrGamoo/Submit/Compile/Block.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 70 CC 9 SCAR 35.8
CC
9
Cov
0%
compile
56.0
_compile_attr
12.0
new
2.0
CRAP 36.0
1 # -*- perl -*-
2  
3 # Copyright (c) 2009 AdCopy
4 # Author: Jeff Weisberg
5 # Created: 2009-Oct-28 16:35 (EDT)
6 # Function:
7 #
8 # $Id: Block.pm,v 1.1 2010/11/01 18:42:00 jaw Exp $
9  
10 package AC::MrGamoo::Submit::Compile::Block;
11 use strict;
12  
13 my $UCLASS = 'AC::MrGamoo::User';
14  
15 sub new {
16 my $class = shift;
17  
18 return bless {}, $class;
19 }
20  
21 sub compile {
22 my $me = shift;
23 my $inc = shift;
24  
25 my $prog = "{\n";
26  
27 my $class = $me->{attr}{in_package} || $UCLASS;
28 $prog .= "package $class;\n";
29 if( $class eq $UCLASS ){
30 $prog .= "our \$R;\n";
31 }else{
32 $prog .= "our \$R = \$$UCLASS\::R;\n";
33 }
34  
35 if( !defined($me->{attr}{use_strict}) || $me->{attr}{use_strict} ){
36 $prog .= "use strict;\n";
37 }
38  
39 if( $inc ){
40 $prog .= $inc;
41 }
42  
43 if( $me->{init} ){
44 $prog .= $me->{init};
45 }
46  
47 $prog .= " {\n";
48 $prog .= _compile_attr( $me->{attr} );
49 for my $k qw(code cleanup){
50 next unless $me->{$k};
51 next if( ref $me->{$k} );
52  
53 $prog .= " $k => sub {\n$me->{$k}\n },\n";
54 }
55 $prog .= " };\n}\n";
56  
57 return $prog;
58 }
59  
60 sub _compile_attr {
61 my $h = shift;
62  
63 my $x = " attr => {\n";
64 for my $k (keys %$h){
65 my $v = $h->{$k};
66 next if ref $v;
67 next if $k =~ /\W/;
68 $v =~ s/(["\\])/\\$1/g;
69 $x .= " \"$k\" => \"$v\",\n";
70 }
71  
72 $x .= " },\n";
73 }
74  
75  
76 1;