0

我试图让 Code Closure 工作,但不幸的是,总是抛出一个错误。

这是代码:

use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Response;

my $name = 'test.js';
my $agent = new LWP::UserAgent();
$agent->agent("curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18");

$res = $agent->request(POST 'http://closure-compiler.appspot.com/compile',
           content_type => 'multipart/form-data',
           content      => [
                   output_info => 'compiled_code',
                           compilation_level => 'SIMPLE_OPTIMIZATIONS',
                   output_format => 'text',
                   js_code => [File::Spec->rel2abs($name)]
                       ]);

if ($res->is_success) {
    $minified = $res->decoded_content;
    print $minified;die;
}

我收到以下错误:

错误(13):没有输出信息可产生,但已请求编译。

这是我使用的 api 参考: http ://code.google.com/intl/de-DE/closure/compiler/docs/api-ref.html

希望有人知道这里出了什么问题。谢谢。

4

2 回答 2

2
#!/usr/bin/perl

use strict; use warnings;

use File::Slurp;
use LWP::UserAgent;

my $agent = LWP::UserAgent->new;
my $script = 'test.js';

my $response = $agent->post(
    'http://closure-compiler.appspot.com/compile',
    content_type => 'application/x-www-form-urlencoded',
    content => [
        compilation_level => 'SIMPLE_OPTIMIZATIONS',
        output_info => 'compiled_code',
        output_format => 'text',
        js_code => scalar read_file($script),
    ],
);

if ($response->is_success) {
    my $minified = $response->decoded_content;
    print $minified;
}

输出:

C:\Temp> 猫 test.js
// 在此处添加您的代码
功能你好(名称){
  alert('你好,' + 姓名);
}
你好('新用户');



C:\温度> t
function hello(a){alert("Hello, "+a)}hello("新用户");
于 2010-08-14T01:01:19.210 回答
1

将要编译的实际代码作为 js_code 传递。尝试(删除 form-data content_type 标头):

use File::Slurp "read_file";
...
     js_code => scalar( read_file($name) ),

我看到您正在尝试使用 POST 的文件上传功能;您在 API 文档中看到了什么让您认为这可行?如果那里有东西,我看不到它。

于 2010-08-14T00:52:41.627 回答