|
From: Chris W. <la...@us...> - 2001-11-27 12:09:39
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page
In directory usw-pr-cvs1:/tmp/cvs-serv16072/OpenInteract/Page
Modified Files:
Database.pm File.pm Http.pm
Log Message:
change to class methods
Index: Database.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page/Database.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Database.pm 2001/10/25 14:58:50 1.4
--- Database.pm 2001/11/27 12:09:36 1.5
***************
*** 6,12 ****
sub load {
! my ( $self ) = @_;
my $R = OpenInteract::Request->instance;
! my $page_content = eval { $self->page_content };
if ( $@ ) {
$R->scrib( 0, "Error retrieving content from database. Error: $@\n",
--- 6,12 ----
sub load {
! my ( $class, $page ) = @_;
my $R = OpenInteract::Request->instance;
! my $page_content = eval { $page->page_content };
if ( $@ ) {
$R->scrib( 0, "Error retrieving content from database. Error: $@\n",
***************
*** 19,26 ****
sub save {
! my ( $self, $content ) = @_;
my $R = OpenInteract::Request->instance;
! my $page_content = eval { $self->page_content } || $R->page_content->new;
! $page_content->{location} = $self->{location};
if ( ! ref $content ) {
--- 19,26 ----
sub save {
! my ( $class, $page, $content ) = @_;
my $R = OpenInteract::Request->instance;
! my $page_content = eval { $page->page_content } || $R->page_content->new;
! $page_content->{location} = $page->{location};
if ( ! ref $content ) {
***************
*** 42,47 ****
sub remove {
! my ( $self ) = @_;
! my $page_content = eval { $self->page_content };
return $page_content->remove;
}
--- 42,47 ----
sub remove {
! my ( $class, $page ) = @_;
! my $page_content = eval { $page->page_content };
return $page_content->remove;
}
Index: File.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page/File.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** File.pm 2001/10/25 14:58:50 1.4
--- File.pm 2001/11/27 12:09:36 1.5
***************
*** 17,24 ****
sub load {
! my ( $self ) = @_;
my $R = OpenInteract::Request->instance;
! my $full_location = _create_file_location( $self );
unless ( -f $full_location ) {
$R->scrib( 1, "File ($full_location) does not exist! Bailing on load()..." );
--- 17,24 ----
sub load {
! my ( $class, $page ) = @_;
my $R = OpenInteract::Request->instance;
! my $full_location = $class->_create_file_location( $page );
unless ( -f $full_location ) {
$R->scrib( 1, "File ($full_location) does not exist! Bailing on load()..." );
***************
*** 43,47 ****
# between them
! $content =~ s|<body>(.*)?</body>|$1|i;
return $content;
--- 43,47 ----
# between them
! $content =~ s|<body>(.*?)</body>|$1|i;
return $content;
***************
*** 53,59 ****
sub save {
! my ( $self, $content ) = @_;
my $R = OpenInteract::Request->instance;
! my $full_location = _create_file_location( $self );
$R->DEBUG && $R->scrib( 1, "Trying to save content to ($full_location)" );
--- 53,59 ----
sub save {
! my ( $class, $page, $content ) = @_;
my $R = OpenInteract::Request->instance;
! my $full_location = $class->_create_file_location( $page );
$R->DEBUG && $R->scrib( 1, "Trying to save content to ($full_location)" );
***************
*** 69,73 ****
# Ensure the directory where this will go exists
! _create_location_path( $full_location );
open( NEW, "> $tmp_location" ) || die "Cannot open temp file for writing: $!";
--- 69,73 ----
# Ensure the directory where this will go exists
! $class->_create_location_path( $full_location );
open( NEW, "> $tmp_location" ) || die "Cannot open temp file for writing: $!";
***************
*** 106,111 ****
sub remove {
! my ( $self ) = @_;
! my $full_location = _create_file_location( $self );
my $R = OpenInteract::Request->instance;
$R->DEBUG && $R->scrib( 1, "Trying to delete content file ($full_location)" );
--- 106,111 ----
sub remove {
! my ( $class, $page ) = @_;
! my $full_location = $class->_create_file_location( $page );
my $R = OpenInteract::Request->instance;
$R->DEBUG && $R->scrib( 1, "Trying to delete content file ($full_location)" );
***************
*** 118,131 ****
sub _create_file_location {
! my ( $self ) = @_;
my $R = OpenInteract::Request->instance;
my $html_dir = $R->CONFIG->get_dir( 'html' );
$html_dir =~ s|/$||;
! $R->DEBUG && $R->scrib( 1, "Trying to find filesystem location for ($html_dir) ($self->{location})" );
! return join( '', $html_dir, $self->{location} );
}
sub _create_location_path {
! my ( $location ) = @_;
my $R = OpenInteract::Request->instance;
$R->DEBUG && $R->scrib( 1, "See if ($location) exists or needs created" );
--- 118,131 ----
sub _create_file_location {
! my ( $class, $page ) = @_;
my $R = OpenInteract::Request->instance;
my $html_dir = $R->CONFIG->get_dir( 'html' );
$html_dir =~ s|/$||;
! $R->DEBUG && $R->scrib( 1, "Trying to find filesystem location for ($html_dir) ($page->{location})" );
! return join( '', $html_dir, $page->{location} );
}
sub _create_location_path {
! my ( $class, $location ) = @_;
my $R = OpenInteract::Request->instance;
$R->DEBUG && $R->scrib( 1, "See if ($location) exists or needs created" );
Index: Http.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page/Http.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Http.pm 2001/11/26 06:30:14 1.1
--- Http.pm 2001/11/27 12:09:36 1.2
***************
*** 9,13 ****
my ( $AGENT );
-
BEGIN {
$AGENT = LWP::UserAgent->new();
--- 9,12 ----
***************
*** 16,45 ****
sub load {
! my ( $self ) = @_;
! unless ( $self->{content_location} ) {
return "Cannot retrieve content -- no URL specified.";
}
! unless ( $self->{content_location} =~ /^http/ ) {
return "Cannot retrieve content -- invalid URL specified.";
}
my $request = HTTP::Request->new(
! GET => $self->{content_location} );
my $response = $AGENT->request( $request );
if ( $response->is_success ) {
my $content = $response->content;
! $content =~ s|^.*<body||ism;
$content =~ s|</body>.*$||ism;
! }
! else {
! return 'Cannot retrieve content -- code ' .
! $response->code . ' returned.';
}
}
sub save {
! my ( $self ) = @_;
! warn "--Location $self->{location} cannot be saved, since it's ",
"using HTTP storage.\n";
return 1;
--- 15,47 ----
sub load {
! my ( $class, $page ) = @_;
! my $R = OpenInteract::Request->instance;
! unless ( $page->{content_location} ) {
! $R->scrib( 0, "No content location available -- cannot display" );
return "Cannot retrieve content -- no URL specified.";
}
! unless ( $page->{content_location} =~ /^http/ ) {
! $R->scrib( 0, "Content location invalid ($page->{content_location})" );
return "Cannot retrieve content -- invalid URL specified.";
}
+ $R->scrib( 1, "Trying to fetch URL ($page->{content_location})" );
my $request = HTTP::Request->new(
! GET => $page->{content_location} );
my $response = $AGENT->request( $request );
if ( $response->is_success ) {
my $content = $response->content;
! $content =~ s|^.*<body.*?>||ism;
$content =~ s|</body>.*$||ism;
! return $class->rewrite_content( $content );
}
+ return 'Cannot retrieve content -- code ' . $response->code . ' returned.';
}
+ sub rewrite_content { return $_[1] }
sub save {
! my ( $class, $page ) = @_;
! warn "--Location $page->{location} cannot be saved, since it's ",
"using HTTP storage.\n";
return 1;
***************
*** 48,53 ****
sub remove {
! my ( $self ) = @_;
! warn "--Location $self->{location} cannot be removed, since it's ",
"using HTTP storage.\n";
return 1;
--- 50,55 ----
sub remove {
! my ( $class, $page ) = @_;
! warn "--Location $page->{location} cannot be removed, since it's ",
"using HTTP storage.\n";
return 1;
|