| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
################################################### |
|
2
|
|
|
|
|
|
|
## UPF.pm |
|
3
|
|
|
|
|
|
|
## Andrew N. Hicox |
|
4
|
|
|
|
|
|
|
## |
|
5
|
|
|
|
|
|
|
## Provides auto-population facilities using |
|
6
|
|
|
|
|
|
|
## tags. |
|
7
|
|
|
|
|
|
|
################################################### |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
## Global Stuff ################################### |
|
11
|
|
|
|
|
|
|
package Text::UPF; |
|
12
|
1
|
|
|
1
|
|
5736
|
use 5.6.0; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
56
|
|
|
13
|
|
|
|
|
|
|
#use warnings; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
|
16
|
|
|
|
|
|
|
require Text::Wrapper; |
|
17
|
1
|
|
|
1
|
|
8164
|
use AutoLoader qw(AUTOLOAD); |
|
|
1
|
|
|
|
|
2183
|
|
|
|
1
|
|
|
|
|
7
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
## Class Global Values ############################ |
|
20
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
21
|
|
|
|
|
|
|
our $VERSION = '1.0.5'; |
|
22
|
|
|
|
|
|
|
our $errstr = (); |
|
23
|
|
|
|
|
|
|
our @EXPORT_OK = ($VERSION, $errstr); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
## new ############################################ |
|
26
|
|
|
|
|
|
|
sub new { |
|
27
|
0
|
|
|
0
|
0
|
|
my %p = @_; |
|
28
|
0
|
|
|
|
|
|
my $obj = bless ({ |
|
29
|
|
|
|
|
|
|
#the tagset |
|
30
|
|
|
|
|
|
|
'tagin' => "", |
|
31
|
|
|
|
|
|
|
'tagout' => "", |
|
32
|
|
|
|
|
|
|
#view to get forms from in GetFormDB |
|
33
|
|
|
|
|
|
|
"Form View" => "", |
|
34
|
|
|
|
|
|
|
"Form Name" => "", |
|
35
|
|
|
|
|
|
|
"Form Text" => "", |
|
36
|
|
|
|
|
|
|
#form name of standard disclaimer |
|
37
|
|
|
|
|
|
|
"Disclaimer"=> "", |
|
38
|
|
|
|
|
|
|
#options to pass to DBIx::YAWM::new |
|
39
|
|
|
|
|
|
|
"DBAccess" => { |
|
40
|
|
|
|
|
|
|
#default values for getting forms from db view |
|
41
|
|
|
|
|
|
|
"Server" => "", |
|
42
|
|
|
|
|
|
|
"DBType" => "", |
|
43
|
|
|
|
|
|
|
"User" => "", |
|
44
|
|
|
|
|
|
|
"Pass" => "", |
|
45
|
|
|
|
|
|
|
"SID" => "", |
|
46
|
|
|
|
|
|
|
"Port" => "" |
|
47
|
|
|
|
|
|
|
}, |
|
48
|
|
|
|
|
|
|
#wrap lines larger than |
|
49
|
|
|
|
|
|
|
'Columns' => "", |
|
50
|
|
|
|
|
|
|
#quote the disclaimer with this |
|
51
|
|
|
|
|
|
|
'DiscQuote' => "" |
|
52
|
|
|
|
|
|
|
}); |
|
53
|
|
|
|
|
|
|
#delete null parameters from the object |
|
54
|
0
|
|
|
|
|
|
foreach (keys %{$obj}){ |
|
|
0
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if (ref ($obj->{$_}) eq "HASH"){ |
|
56
|
0
|
0
|
|
|
|
|
foreach my $par (keys %{$obj->{$_}}){ if ($obj->{$_}->{$par} =~/^$/){ delete($obj->{$_}->{$par}); } } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
}else{ |
|
58
|
0
|
0
|
|
|
|
|
if ($obj->{$_} =~/^$/){ delete($obj->{$_}); } |
|
|
0
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
#overrides and extra directives go here |
|
62
|
0
|
0
|
|
|
|
|
if (exists($p{Port})){ $obj->{DBAccess}->{Port} = $p{Port}; delete($p{Port}); } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
foreach (keys %p){ $obj->{$_} = $p{$_}; } |
|
|
0
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return ($obj); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
## Populate ####################################### |
|
68
|
|
|
|
|
|
|
sub Populate { |
|
69
|
|
|
|
|
|
|
#local vars |
|
70
|
0
|
|
|
0
|
0
|
|
my ($self, %p) = @_; |
|
71
|
|
|
|
|
|
|
#local for easier regex syntax |
|
72
|
0
|
|
|
|
|
|
my ($tagin,$tagout) = ($self->{tagin},$self->{tagout}); |
|
73
|
|
|
|
|
|
|
#if there's no Text, look for Form to get from DB, or as last resort |
|
74
|
|
|
|
|
|
|
#try to open File, if it exists |
|
75
|
0
|
0
|
|
|
|
|
unless (exists ($p{Text})){ |
|
76
|
0
|
0
|
|
|
|
|
if (exists ($p{Form})){ |
|
|
|
0
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
unless ($p{Text} = $self->GetFormDB(Form => $p{Form})){ |
|
78
|
0
|
|
|
|
|
|
$self->{errstr} = "failed to get form ($p{Form}) from database! $self->{errstr}"; |
|
79
|
0
|
|
|
|
|
|
return (undef); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
}elsif (exists ($p{File})){ |
|
82
|
0
|
0
|
|
|
|
|
unless ($p{Text} = $self->GetFormFile(File => $p{File})){ |
|
83
|
0
|
|
|
|
|
|
$self->{errstr} = "failed to open form file ($p{File}) $self->{errstr}"; |
|
84
|
0
|
|
|
|
|
|
return (undef); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
}else{ |
|
87
|
0
|
|
|
|
|
|
$self->{errstr} = "Text, Form, or File is a required option for Text::UPF::Populate"; |
|
88
|
0
|
|
|
|
|
|
return (undef); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
#while there are 's left to read |
|
92
|
0
|
|
|
|
|
|
while ($p{Text} =~/($tagin)(.+?)($tagout)/i){ |
|
93
|
0
|
|
|
|
|
|
my ($tag_in,$method,$tag_out) = ($1,$2,$3); |
|
94
|
0
|
|
|
|
|
|
my $whole_tag = quotemeta("$tag_in$method$tag_out"); |
|
95
|
0
|
|
|
|
|
|
my ($directive,$replace) = (); |
|
96
|
0
|
0
|
|
|
|
|
if (exists ($p{Data}->{$method})){ |
|
|
|
0
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#if we have the data, just replace it |
|
98
|
0
|
|
|
|
|
|
$p{Text} =~s/$whole_tag/$p{Data}->{$method}/ig; |
|
99
|
0
|
|
|
|
|
|
next; |
|
100
|
|
|
|
|
|
|
}elsif ($method =~/(.+)\{(.+)\}/i){ |
|
101
|
|
|
|
|
|
|
#look for directive in the method |
|
102
|
0
|
|
|
|
|
|
($method,$directive) = ($1,$2); |
|
103
|
0
|
|
|
|
|
|
my $str = '$replace = $self->$method(directive => $directive, %p)'; |
|
104
|
0
|
|
|
|
|
|
eval ($str); |
|
105
|
0
|
0
|
|
|
|
|
if ($@ =~/^can't locate object method/i){ |
|
106
|
0
|
|
|
|
|
|
$replace = "[Unsuported Population Method: $method]"; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
0
|
|
|
|
|
|
$p{Text} =~s/$whole_tag/$replace/ig; |
|
109
|
|
|
|
|
|
|
}else{ |
|
110
|
|
|
|
|
|
|
#maybe we need to call a subroutine? |
|
111
|
0
|
|
|
|
|
|
my $str = '$replace = $self->$method(%p)'; |
|
112
|
0
|
|
|
|
|
|
eval ($str); |
|
113
|
0
|
0
|
|
|
|
|
if ($@ =~/^can't locate object method/i){ |
|
114
|
0
|
|
|
|
|
|
$replace = "[Undefined Population Method: $method]"; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
0
|
|
|
|
|
|
$p{Text} =~s/$whole_tag/$replace/ig; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
#wrap the lines |
|
120
|
0
|
0
|
|
|
|
|
unless (exists($self->{wrapper})){ |
|
121
|
0
|
|
|
|
|
|
$self->{wrapper} = Text::Wrapper->new(columns => $self->{'Columns'}); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
0
|
0
|
|
|
|
|
unless ($p{NoWrap}){ $p{Text} = $self->{wrapper}->wrap($p{Text}); } |
|
|
0
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#duff man says ... oh yeaaaah! |
|
125
|
0
|
|
|
|
|
|
return ($p{Text}); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
## Destroy ######################################## |
|
129
|
|
|
|
|
|
|
#clean up db connection (if it belongs to us), destroy object |
|
130
|
|
|
|
|
|
|
sub Destroy { |
|
131
|
0
|
|
|
0
|
0
|
|
my ($self) = shift(); |
|
132
|
0
|
0
|
0
|
|
|
|
if (($self->{myDB}) && ($self->{DBTool})){ $self->{DBTool}->Destroy(); } |
|
|
0
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$self = undef; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
## True for perl include ########################## |
|
137
|
|
|
|
|
|
|
1; |
|
138
|
|
|
|
|
|
|
__END__ |