Created
June 2, 2011 16:09
-
-
Save chiragmatkar/1004718 to your computer and use it in GitHub Desktop.
File Object (Java cloning)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; | |
| package File; | |
| =head1 | |
| Title : new | |
| Usage : my $fileobj=File->new(-file=>"D\\testing.txt") | |
| Function : Creates a File Object | |
| Returns : None | |
| Argument : a file or file handle | |
| =cut | |
| sub new{ | |
| my $class=shift; | |
| my $self={@_}; | |
| bless ($self,$class); | |
| $self->_initialize(@_); | |
| return $self; | |
| } | |
| =head1 | |
| Title : file_read | |
| Usage : $fileobj->file_read() | |
| Function : Reads a File | |
| Returns : filecontents buffer | |
| Argument : file object (optional) | |
| =cut | |
| sub file_read{ | |
| my $self=shift; | |
| open(FH,"$self->{file}") or die $!; | |
| $self->{filebuf} = join '', <FH>; | |
| close(FH); | |
| return $self->{filebuf}; | |
| } | |
| =head2 _initialize | |
| Private Method to initialize contructor arguments in a hash | |
| =cut | |
| sub _initialize { | |
| my $self = shift; | |
| # my @params = qw(verbose conf file); | |
| while ( @_ ) { | |
| ( my $key = shift ) =~ s/^-//; | |
| $self->{$key} = shift; | |
| } | |
| if (exists($self->{mode})) | |
| { | |
| $self->mode($self->{mode}); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment