App-FileComposer

 view release on metacpan or  search on metacpan

lib/App/FileComposer.pm  view on Meta::CPAN

	my $extension = $1;
	
	### Search the file we want 
	opendir DIRHANDLE, $origin
	or croak BRIGHT_RED, 
  " The $origin directory does not exist\n".
  "run in Terminal: \$ mkdir $origin or mkscript --reconf", RESET;
		
    
    #// define a flag 
    our $i_found;		
		
          		while(readdir DIRHANDLE)  {
				              	next unless /$extension\b/i; 	

                        #// flag
					              $i_found = $_; # the sample file we want !
	
				              }close(DIRHANDLE);	
			
									
						
						if ($i_found) {		return $i_found;   }
						  else{
						
						      ###stop the code if don't find the extension we want
      						die BRIGHT_RED, 
		      				"No sample file in $origin containing extension $extension \n", 
				      		RESET;
                }
							
}



sub write {
	my ($self, $where) = @_; 
	my $origin = $self->{'origin'};	
	my $filename = $self->{'filename'};


  #// flag
	our $i_found;
	
  #// dies if we have not the file in $i_found
	croak ' 
  The source guidelines were not loaded internally,
  you forgot to load them..
  Set: $obj->load() method in your code before use write()
  ' unless defined $i_found;



   		{

        #// define a temp file
        my $temp = "temp.$$";

        #// copy data in sample file to the temp file 
        #// after that, rename it 
        open INPUT , '<', "$origin/$i_found" 
            or die "error: $! \n";

                  # my @filesize = <INPUT>;
                  
        open OUTPUT, '>>', "./$temp" 
            or die "cannot write to $temp, error: $!\n";
        my $bar = Progress::Awesome->new(1000, style => 'rainbow', title => 'loading...');

         while (<INPUT>) {
                  print OUTPUT $_;
                  $bar->inc();
                  select(undef, undef, undef, 0.010);
                  

               }

                close(INPUT);
                close(OUTPUT);
                  rename $temp, $filename;
                  $bar->finish;
 

   
     		}

}


1; # End of App::FileComposer



( run in 0.898 second using v1.01-cache-2.11-cpan-13bb782fe5a )