line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/coderepos/lang/perl/R-Writer/trunk/lib/R/Writer/Var.pm 43085 2008-03-01T12:28:42.888222Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2008 Daisuke Maki |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package R::Writer::Var; |
7
|
6
|
|
|
6
|
|
33
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
190
|
|
8
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
151
|
|
9
|
6
|
|
|
6
|
|
30
|
use base qw(Class::Accessor::Fast); |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
3234
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw(name value writer); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new |
14
|
|
|
|
|
|
|
{ |
15
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
16
|
0
|
|
0
|
|
|
|
my $self = $class->SUPER::new({ name => $_[0], value => $_[1], writer => $_[2] || R::Writer::R() }); |
17
|
0
|
|
|
|
|
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub as_string |
21
|
|
|
|
|
|
|
{ |
22
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
my $c = shift; |
24
|
0
|
|
|
|
|
|
my $var = $self->name; |
25
|
0
|
|
|
|
|
|
my $value = $self->value; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $s = ""; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
my $ref = defined $value ? ref $value : undef; |
30
|
0
|
0
|
0
|
|
|
|
if (!defined $value) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$s = "$var;"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif (! $ref) { |
34
|
0
|
|
|
|
|
|
$s = "$var <- $value;"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif ($ref eq 'ARRAY' || $ref eq 'HASH') { |
37
|
0
|
|
|
|
|
|
$s = "$var <- " . $self->encoder->encode($value) . ";" |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ($ref eq 'CODE') { |
40
|
0
|
|
|
|
|
|
$s = "$var <- " . $c->__obj_as_string($value->()); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif ($ref =~ /^R::Writer/) { |
43
|
0
|
|
|
|
|
|
$s = "$var <- " . $value->as_string($c); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif ($ref eq 'REF') { |
46
|
0
|
|
|
|
|
|
my $j = $self->new; |
47
|
0
|
|
|
|
|
|
$j->var($var => $$value); |
48
|
0
|
|
|
|
|
|
$s = $j->as_string; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ($ref eq 'SCALAR') { |
51
|
0
|
0
|
|
|
|
|
if (defined $$value) { |
52
|
0
|
|
|
|
|
|
my $v = $self->__obj_as_string($value); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$s = "var $var = $v;"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
0
|
|
|
|
|
|
$s = "var $var;"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
eval { |
61
|
0
|
|
|
|
|
|
R::Writer::Var->new( |
62
|
|
|
|
|
|
|
$value, |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
name => $var, |
65
|
|
|
|
|
|
|
jsw => $self |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $s; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |