Update of /cvsroot/sandweb/sandweb/lib/SandWeb
In directory usw-pr-cvs1:/tmp/cvs-serv12514
Modified Files:
File.pm
Log Message:
ah.. much better :) private methods invoked by public methods.
no more creating file objects inside file objects.
object orientation kicks ass.
Index: File.pm
===================================================================
RCS file: /cvsroot/sandweb/sandweb/lib/SandWeb/File.pm,v
retrieving revision 1.19
retrieving revision 1.20
diff -U2 -r1.19 -r1.20
--- File.pm 2001/12/20 02:34:46 1.19
+++ File.pm 2001/12/20 02:51:13 1.20
@@ -100,12 +100,6 @@
my $log = $self->{'log_obj'};
+ my $return = _do_file_write( 'contents' => "test" );
- my $file = SandWeb::File->new(
- 'location' => "$location",
- 'filename' => "$filename",
- );
-
- $file->file_write( 'contents' => "test" );
-
return $return;
}
@@ -157,6 +151,6 @@
);
- my @fromfile = $file->file_read();
- $file->file_write( 'contents' => "@fromfile" );
+ my @fromfile = _do_file_read();
+ _do_file_write( 'contents' => "@fromfile" );
return $return;
@@ -183,7 +177,8 @@
my $log = $self->{'log_obj'};
- open (FILE, "< $location/$filename");
- my $contents = <FILE>;
- close FILE;
+ my $contents = _do_file_read(
+ 'location' => "$location",
+ 'filename' => "$filename",
+ );
return $contents;
@@ -196,10 +191,12 @@
my $location = $self->{'location'};
my $filename = $self->{'filename'};
-
my $contents = $args{'contents'};
- open (FILE, ">$location/$filename");
- print FILE $contents;
- my $return = close FILE;
+ my $return = _do_file_write(
+ 'location' => "$location",
+ 'filename' => "$filename",
+ 'contents' => "$contents",
+ );
+
return $return;
}
@@ -215,4 +212,26 @@
'download',
);
+}
+
+sub _do_file_write {
+ my %args = @_;
+ my $location = $args{'location'};
+ my $filename = $args{'filename'};
+ my $contents = $args{'contents'};
+
+ open (FILE, ">$location/$filename");
+ print FILE $contents;
+ my $return = close FILE;
+ return $return;
+}
+
+sub _do_file_read {
+ my %args = @_;
+ my $location = $args{'location'};
+ my $filename = $args{'filename'};
+
+ open (FILE, "<$location/$filename");
+ my $contents = <FILE>;
+ return $contents;
}
|