1 |
BEGIN
|
2 |
{
|
3 |
print "ActiveDoc::Activate: I AM used!","\n";
|
4 |
};
|
5 |
|
6 |
#
|
7 |
# Easy Setup of cache etc for ActiveDoc enactivation
|
8 |
#
|
9 |
# Author : C.Williams
|
10 |
#
|
11 |
# Interface
|
12 |
# ---------
|
13 |
# new(location) : Create a new activeation area at location
|
14 |
# activatedoc($url) : Return the object corresponding to the activedoc
|
15 |
# provided by the url
|
16 |
# get(url) : download url and return the filename
|
17 |
# of the processed doc
|
18 |
|
19 |
package ActiveDoc::Activate;
|
20 |
use ActiveDoc::ActiveDoc;
|
21 |
use ActiveDoc::ActiveStore;
|
22 |
use Utilities::Verbose;
|
23 |
|
24 |
@ISA=qw(Utilities::Verbose);
|
25 |
|
26 |
|
27 |
sub new {
|
28 |
my $class=shift;
|
29 |
my $self={};
|
30 |
bless $self, $class;
|
31 |
|
32 |
# -- initiate cgi work area
|
33 |
$self->{workarea}=shift;
|
34 |
$self->_initarea($self->{workarea});
|
35 |
return $self;
|
36 |
}
|
37 |
|
38 |
sub _initarea {
|
39 |
my $self=shift;
|
40 |
my $dir=shift;
|
41 |
$self->{dbstore}=ActiveDoc::ActiveStore->new($dir);
|
42 |
$self->{ad}=ActiveDoc::ActiveDoc->new($self->{dbstore});
|
43 |
}
|
44 |
|
45 |
sub get {
|
46 |
my $self=shift;
|
47 |
my $url=shift;
|
48 |
$self->verbose("Attempt to get $url");
|
49 |
my $file;
|
50 |
# We dont want it messaging
|
51 |
require FileHandle;
|
52 |
local (*FHOLD);
|
53 |
local (*FHOLDERR);
|
54 |
# - copy STDERR and STDOUT
|
55 |
open(FHOLD,">&STDOUT");
|
56 |
open(FHOLDERR,">&STDERR");
|
57 |
|
58 |
# - redirect STDERR and STDOUT
|
59 |
my $rfile="/tmp/$$";
|
60 |
$self->verbose("Redirecting STDOUT to $rfile");
|
61 |
open(STDOUT, ">".$rfile) || die "Unable to open $!\n";
|
62 |
open(STDERR, ">&STDOUT") || die "Unable to open $!\n";
|
63 |
|
64 |
# -- call
|
65 |
my @rv=();
|
66 |
eval { $file=$self->{ad}->getfile($url)->ProcessedFile() };
|
67 |
if ( (! defined $file) || ($file eq "") ) {
|
68 |
push @rv, (undef,$rfile);
|
69 |
}
|
70 |
else {
|
71 |
push @rv, ($file,$rfile);
|
72 |
}
|
73 |
close STDOUT;
|
74 |
close STDERR;
|
75 |
|
76 |
# -- restore STDOUT & STDERR
|
77 |
open(STDOUT, ">&FHOLD");
|
78 |
open(STDERR, ">&FHOLDERR");
|
79 |
close FHOLD;
|
80 |
close FHOLDERR;
|
81 |
|
82 |
$self->verbose("Redirection Finnished of STDOUT");
|
83 |
return (@rv);
|
84 |
}
|
85 |
|
86 |
sub activatedoc {
|
87 |
my $self=shift;
|
88 |
my $url=shift;
|
89 |
|
90 |
my $obj;
|
91 |
$self->verbose("Attempting activation of $url");
|
92 |
if ( eval { $obj=$self->{ad}->activatedoc($url) } ) {
|
93 |
return ($obj, $@);
|
94 |
}
|
95 |
else {
|
96 |
return (undef, $@);
|
97 |
}
|
98 |
}
|