App-Framework

 view release on metacpan or  search on metacpan

lib/App/Framework/Extension/Filter.pm  view on Meta::CPAN

		foreach my $line (@{$state_href->{output_lines}})
		{
			$this->_wr_output($state_href, $opts_href, $line) ;
		}	
	}
	
	# close output file
	$this->_close_output($state_href, $opts_href) ;
}



#----------------------------------------------------------------------------

=item B<_open_output($state_href, $opts_href)>

Open the file (or STDOUT) depending on settings
 
=cut


sub _open_output
{
	my $this = shift ;
	my ($state_href, $opts_href) = @_ ;

	$this->set('out_fh' => undef) ;

$this->_dbg_prt(["_open_output\n"]) ;
	
	my $outfile ;
	if ($this->inplace)
	{
		## Handle in-place editing
		$outfile = $state_href->{file} ;
$this->_dbg_prt([" + inplace file=$outfile\n"]) ;
	}
	elsif ($this->outfile)
	{
		## See if writing to dir
		my $dir = $this->outdir ;
		if ($dir)
		{
			## create path
			mkpath([$dir], $this->debug, 0755) ;
		}
		$dir ||= '.' ;
		
		my %opts = $this->options() ;
		my %app_vars = $this->vars() ;
		my %filter ;
		$filter{'filter_fmt'} = $this->outfile ;
		$filter{'filter_file'} = $state_href->{file} ;
		$filter{'filter_filenum'} = $state_href->{file_number} ;
		my ($base, $path, $ext) = fileparse($state_href->{file}, '\..*') ;
		$filter{'filter_name'} = $base ;
		$filter{'filter_base'} = $base ;
		$filter{'filter_path'} = $path ;
		$filter{'filter_ext'} = $ext ;

		$this->expand_keys(\%filter, [\%opts, \%app_vars, \%ENV]) ;
		
		$outfile = $filter{'filter_fmt'} ;
		
$this->_dbg_prt([" + eval=$@\n"]) ;
$this->_dbg_prt([" + outfile=$outfile: dir=$dir fmt=$filter{'filter_fmt'} file=$filter{'filter_file'} num=$filter{'filter_filenum'} base=$base path=$path\n"]) ;
		
		$outfile = File::Spec->catfile($dir, $outfile) ;
	}
	
	## Output file specified?
	if ($outfile)
	{
		$outfile = File::Spec->rel2abs($outfile) ;
		my $infile = File::Spec->rel2abs($state_href->{file}) ;

		if ($outfile eq $infile)
		{
			# In place editing - make sure flag is set
			$this->inplace(1) ;

$this->_dbg_prt([" + inplace $outfile\n"]) ;
		}

#		else
#		{
			## Open output
			open my $outfh, ">$outfile" or $this->throw_fatal("Unable to write \"$outfile\" : $!") ;
			$this->out_fh($outfh) ;

$this->_dbg_prt([" + opened $outfile fh=$outfh\n"]) ;
			
			$state_href->{outfile} = $outfile ;
#		}
		
	}
	else
	{
		## STDOUT
		$this->out_fh(\*STDOUT) ;
	}
}

#----------------------------------------------------------------------------

=item B<_close_output($state_href, $opts_href)>

Close the file if open
 
=cut


sub _close_output
{
	my $this = shift ;
	my ($state_href, $opts_href) = @_ ;

	my $fh = $this->out_fh ;
	$this->set('out_fh' => undef) ;
	
	if ($this->outfile)



( run in 0.564 second using v1.01-cache-2.11-cpan-5623c5533a1 )