未定义的子程序& main :: vars调用

时间:2015-07-27 13:19:57

标签: git perl

我正在尝试使用git检出存储库。我已经在.cfg文件中指定了git repo路径和所有目录路径。现在我尝试通过获取值作为哈希来访问.cfg文件中的文件夹路径和repo路径。我完全根据我对Perl的理解验证了我的代码。但过去两天我真的厌倦了这一点。我得到的错误是

Undefined subroutine &main::vars called at Create_UnitTesting_Environment_and_Ru
n_UnitTestSuites.pl line 28.

有时喜欢这个

Can't call method "vars" on an undefined value at Create_UnitTesting_Environment
_and_Run_UnitTestSuites.pl line 28.

我无法弄清楚 - 我错过了全球宣布的内容。请有人帮我解决这个问题。

    use Config::Simple;
    use vars;
    use File::Copy;
    use File::Copy::Recursive qw( dircopy );
    use Git::Repository;
    use Log::StdLog { level => 'all', file => "$0.log" };
    use strict;
    use warnings;
    use TryCatch;
    my ( $cfg, $current_dir, %config, $package_path, $installation_path );
    # Load configuration file
    $cfg    = new Config::Simple( 'D:\\Projects\\TeamCity\\LensXRay_V6_with_git_Trigger\\Create_UnitTesting_Environment_and_Run_UnitTestSuites.cfg' );
    # Getting the values as a hash
    #error line no 28
    %config     = $cfg->vars();
    my ($gitrepo_path, $git_checkout_path, $UnitTest_deployment, $UnitTest_bin_path);

$gitrepo_path       = $config{"CFG.gitrepo_path"};
$git_checkout_path  = $config{"CFG.gitcheckout_path"};
$UnitTest_bin_path  = $config{"CFG.UnitTest_bin_path"};
$UnitTest_deployment    = $config{"CFG.UnitTest_deployment"};

CheckoutFromGit();


# print $package_path ."\n". $installation_path . "\n\n\n\n";


sub CheckoutFromGit
{
    print {*STDLOG} info  => "Checking out from GIT...";
        if( -d "$git_checkout_path" )
        {
            try
            {
                my ($work_dir, $git_run, $msg);

                $work_dir   =  "$git_checkout_path";

                $git_run    = Git::Repository->new( work_tree=>$work_dir );

                print {*STDLOG} info  => "Checking out ". $gitrepo_path . "...";

                print {*STDLOG} info  => "$msg";


                print {*STDLOG} info  => "$msg";
            }
            catch { print {*STDLOG} error  => "Checking out $gitrepo_path failed"; die "Checking out $gitrepo_path.git failed"; }
        }
        else
        {
            try
            {
                my ($git_url, $work_dir);
                chdir $git_checkout_path;


                $git_url = "$gitrepo_path.git";
                $work_dir = "$git_checkout_path/$gitrepo_path";             

                my $msg = Git::Repository->run(clone=>$git_url=>$work_dir);
                print {*STDLOG} info  => "Cloning $gitrepo_path.git " . $msg;
            }
            catch { print {*STDLOG} error  => "Cloning $gitrepo_path.git failed"; die "Cloning $gitrepo_path.git failed"; }
        }

    print {*STDLOG} info  => "Checked out Successfully";
}

0 个答案:

没有答案