App-Framework

 view release on metacpan or  search on metacpan

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


	my $class = ref($obj) || $obj ;

	## create object dynamically
	my $this = App::Framework::Core->inherit($class, %args) ;

#print "Filter - $class ISA=@ISA\n" if $class_debug ;

	## Set options
	$this->feature('Options')->append_options(\@OPTIONS) ;
	
	## Update option defaults
	$this->feature('Options')->defaults_from_obj($this, [keys %FIELDS]) ;

	## Set args
	$this->feature('Args')->append_args(\@ARGS) ;

#$this->debug(2) ;
	
	## hi-jack the app function
	$this->extend_fn(
		'app_fn'		=> sub {$this->filter_run(@_);},
		'app_start_fn'		=> sub {$this->_filter_start(@_);},
		'app_end_fn'		=> sub {$this->_filter_end(@_);},
	) ;

	return($this) ;
}



#============================================================================================

=back

=head2 CLASS METHODS

=over 4

=cut

#============================================================================================

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

=item B<init_class([%args])>

Initialises the object class variables.

=cut

sub init_class
{
	my $class = shift ;
	my (%args) = @_ ;

	# Add extra fields
	$class->add_fields(\%FIELDS, \%args) ;

	# init class
	$class->SUPER::init_class(%args) ;

}


#============================================================================================

=back

=head2 OBJECT METHODS

=over 4

=cut

#============================================================================================

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

=item B<filter_run($app, $opts_href, $args_href)>

Filter the specified file(s) one at a time.
 
=cut


sub filter_run
{
	my $this = shift ;
	my ($app, $opts_href, $args_href) = @_ ;

	## save for later
	$this->_filter_opts($opts_href) ;

$this->_dbg_prt(["Args=", $args_href, "Opts=", $opts_href]) ;
	
	# Get command line arguments
	my @args = @{ $args_href->{'file'} || [] } ;
	my @args_fh = @{ $args_href->{'file_fh'} || [] } ;

	## check for in-place editing on STDIN
	if ($opts_href->{inplace})
	{
		if ( (scalar(@args) == 1) && ($args_fh[0] == \*STDIN) )
		{
			$this->throw_fatal("Cannot do in-place editing of standard input") ;
		}
	}

	$this->_dispatch_entry_features(@_) ;

#$this->debug(2) ;

$this->_dbg_prt(["#!# Hello, Ive started filter_run()...\n"]) ;

	## Update from options
	$this->feature('Options')->obj_vars($this, [keys %FIELDS]) ;

	## Set up filter state
	my $state_href = $this->_filter_state ;
	$state_href->{num_files} = scalar(@args) ;



( run in 0.755 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )