| 1 | package NKTI::general::file::create; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | # Items to export into callers namespace by default. Note: do not export | ||
| 7 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 8 | # Do not simply export all your public functions/methods/constants. | ||
| 9 | |||
| 10 | # This allows declaration use Malltronik::general::file::create ':all'; | ||
| 11 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||
| 12 | # will save memory. | ||
| 13 | |||
| 14 | # Constructor | ||
| 15 | # ------------------------------------------------------------ | ||
| 16 | =head1 MODULE new() | ||
| 17 | |||
| 18 | Deskripsi : | ||
| 19 | ---------------------------------------- | ||
| 20 | Module yang berfungsi sebagai konstruktor Module. | ||
| 21 | |||
| 22 | Parameter Modul : | ||
| 23 | ---------------------------------------- | ||
| 24 | _file_name => Parameter yang berisi nama file yang akan dibuat. | ||
| 25 | _dir_loc => Parameter yang berisi lokasi tempat penyimpanan file yang dibuat | ||
| 26 | _isi_file => Parameter yang berisi Isi file yang dibuat. | ||
| 27 | |||
| 28 | =cut | ||
| 29 | sub new { | ||
| 30 | |||
| 31 | # Define scalar for arguments object : | ||
| 32 | # ------------------------------------------------------------ | ||
| 33 | my $class = shift; | ||
| 34 | my $self = { | ||
| 35 | _file_name => shift, | ||
| 36 | _dir_loc => shift, | ||
| 37 | _isi_file => shift | ||
| 38 | }; | ||
| 39 | bless $self, $class; | ||
| 40 | return $self; | ||
| 41 | } | ||
| 42 | |||
| 43 | # Module for Create New File : | ||
| 44 | # ------------------------------------------------------------ | ||
| 45 | =head1 MODULE create() | ||
| 46 | |||
| 47 | Parameter Modul : | ||
| 48 | ---------------------------------------- | ||
| 49 | TIdak ada parameter module, namun aksi dalam module | ||
| 50 | berdasakarkan parameter dari Constructor. | ||
| 51 | |||
| 52 | =cut | ||
| 53 | sub create { | ||
| 54 | |||
| 55 | # Define arguments : | ||
| 56 | # ------------------------------------------------------------ | ||
| 57 | my ($self) = @_; | ||
| 58 | my $filename = $self->{_file_name}; | ||
| 59 | my $destination = $self->{_dir_loc}; | ||
| 60 | my $isi_file = $self->{_isi_file}; | ||
| 61 | |||
| 62 | # Define variable for FileHandle : | ||
| 63 | # ------------------------------------------------------------no | ||
| 64 | my $loc_files = $destination . $filename; | ||
| 65 | |||
| 66 | # Declare Hash for placing result create new file : | ||
| 67 | # ---------------------------------------------------------------- | ||
| 68 | my %data; | ||
| 69 | |||
| 70 | # Create New Files : | ||
| 71 | # ------------------------------------------------------------ | ||
| 72 | open(FILE, '>', $loc_files) or die "File : $loc_files is not exists $!"; | ||
| 73 | print FILE $isi_file; | ||
| 74 | close(FILE); | ||
| 75 | |||
| 76 | # Chcck IF $loc_files is exists : | ||
| 77 | # ------------------------------------------------------------ | ||
| 78 | if (-e $loc_files) | ||
| 79 | { | ||
| 80 | # Placing success result into hash "%data" : | ||
| 81 | # ---------------------------------------------------------------- | ||
| 82 | $data{'result'} = { | ||
| 83 | 'sukses' => 1, | ||
| 84 | 'data' => { | ||
| 85 | 'dirloc' => $destination, | ||
| 86 | 'filename' => $filename, | ||
| 87 | 'fileloc' => $loc_files | ||
| 88 | } | ||
| 89 | }; | ||
| 90 | } | ||
| 91 | # End of check IF $loc_files is exists. | ||
| 92 | # ================================================================ | ||
| 93 | |||
| 94 | # Check IF $loc_files is not exists : | ||
| 95 | # ------------------------------------------------------------ | ||
| 96 | else | ||
| 97 | { | ||
| 98 | # Placing error result into hash "$data" : | ||
| 99 | # ---------------------------------------------------------------- | ||
| 100 | $data{'result'} = { | ||
| 101 | 'sukses' => 0, | ||
| 102 | 'data' => { | ||
| 103 | 'dirloc' => $destination, | ||
| 104 | 'filename' => $filename, | ||
| 105 | 'fileloc' => $loc_files | ||
| 106 | } | ||
| 107 | }; | ||
| 108 | } | ||
| 109 | # End of check IF $loc_files is not exists. | ||
| 110 | # ================================================================ | ||
| 111 | |||
| 112 | # Return result : | ||
| 113 | # ---------------------------------------------------------------- | ||
| 114 | return \%data; | ||
| 115 | } | ||
| 116 | # End of Module for Create New File. | ||
| 117 | # ================================================================ | ||
| 118 | |||
| 119 | 1; | ||
| 120 | __END__ |