📄 getopt.pm
字号:
# vim:ts=4 sw=4# ----------------------------------------------------------------------------------------------------# Name : ETL::Pequel3::GetOpt.pm# Created : 2 May 2006# Author : Mario Gaffiero (gaffie)## Copyright 1999-2007 Mario Gaffiero.# # This file is part of Pequel(TM).# # Pequel is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; version 2 of the License.# # Pequel is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with Pequel; if not, write to the Free Software# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA# ----------------------------------------------------------------------------------------------------# Modification History# When Version Who What# ----------------------------------------------------------------------------------------------------package ETL::Pequel3::GetOpt;require 5.005_62;use strict;use warnings;use stl;# ----------------------------------------------------------------------------------------------------{ package ETL::Pequel3::GetOpt; use base qw(Class::STL::Element); use Class::STL::ClassMembers qw( err catalogue user properties ); use Class::STL::ClassMembers::SingletonConstructor; #NOTE: Singleton because we need to access any opt that were passed in via #CommandLine->main() args from the generator; use ETL::Pequel3::Type::CmdOption; sub new_extra { my $self = shift; use ETL::Pequel3::Error; $self->err(ETL::Pequel3::Error->new()); $self->catalogue(ETL::Pequel3::Catalogue->new()); # Singleton $self->properties($self->catalogue()->properties()); # Singleton $self->user(ETL::Pequel3::Type::CmdOption::Catalogue::User->new()); $self->_get_options(@_, @ARGV); } sub prep_options { my $self = shift; my $POM = shift; map($_->prep($POM), $self->user()->to_array()); } sub exec_options { my $self = shift; my $POM = shift; map($_->exec($POM), $self->user()->to_array()); } sub copy_config { my $self = shift; my $config = shift; map ( $config->exists($_->prop_name())->value($_->data()), grep ( defined($_->prop_name()) && $config->exists($_->prop_name()), $self->user()->to_array() ) ); } sub _get_options { #NOTE: catalogue->options->option_name returns the option value (data) and NOT # a CmdOption object ref; my $self = shift; my @argv = (@_); for (my $i=0; $i <= $#argv; ++$i) { if ($argv[$i] =~ /^\-{1,2}(.*)/ && $self->catalogue()->options()->exists($1)) { my $o = $self->catalogue()->options()->exists($1); $self->user()->push_back ( $o->new ( data => $o->flag() ? 1 : $i < $#argv && $argv[$i+1] !~ /^-/ ? $argv[++$i] : do { defined($o->default()) ? $o->default() : undef; } ) ); $self->properties()->exists($o->long_name()) ->value($self->user()->back()->data()) if (defined($o->prop_name()) && $self->properties()->exists($o->long_name())); } elsif ($argv[$i] =~ /^\-{1,2}(.*)/) # assume its a user_option: { $self->user()->push_back ( ETL::Pequel3::Type::CmdOption::UserOption->new ( long_name => $1, data => $i < $#argv && $argv[$i+1] !~ /^-/ ? $argv[++$i] : 1 # assume flag ) ); $self->properties()->exists($self->user()->back()->long_name()) ->value($self->user()->back()->data()) if ($self->properties()->exists($self->user()->back()->long_name())); } elsif ($argv[$i] =~ /\.(xml|xpq|dump)$/) { $self->user()->push_back( $self->catalogue()->options()->exists('script_filename')->new( data => $argv[$i] ) ); } else { # unknown option } } return $self->user(); }}# ----------------------------------------------------------------------------------------------------1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -