2 ###APPNAME: urlrule_new
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Sat Mar 22 22:56:33 2008
6 ###APPDESC: create new url rule
8 ###APPEXAMPLE: urlrule_new http://www.shuku.net/novels/gulong/bianlang/bianlang.html 2
11 use lib
$ENV{XR_PERL_MODULE_DIR
};
12 use MyPlace
::Script
::Usage qw
/help_even_empty/;
14 exit 0 if(help_even_empty
($0,@ARGV));
16 use MyPlace
::ColorPrint
;
17 use MyPlace
::URLRule qw
/parse_rule/;
19 my %rule = %{parse_rule
(@ARGV)};
21 my $level=$rule{level
};
22 my $source=$rule{source
};
26 app_message
("Rule for $url exists,opened for editing instead\n");
27 system("r-vim \"$source\"&");
32 open VIMED
,"|-","r-vim -c 'file $source' - ";
47 '#use quick parse'=>1,
52 'pass_name_map'=>undef,
70 my ($url,$rule,$html) = @_;
74 #my @html = split(/\n/,$html);
78 pass_count=>scalar(@pass_data),
79 pass_data=>[@pass_data],
89 my $http = MyPlace::Curl->new();
90 my (undef,$html) = $http->get($url);
91 return &_process($url,$rule,$html,@_);
97 print VIMED
<<'USAGE';
101 #================================================================
102 # apply_rule will be called with ($RuleBase,%Rule),the result returned have these meaning:
103 # $result{base} : Base url to build the full url
104 # $result{work_dir} : Working directory (will be created if not exists)
105 # $result{data} : Data array extracted from url,will be passed to $result{action}(see followed)
106 # $result{action} : Command which the $result{data} will be piped to,can be overrided
107 # $result{pipeto} : Same as action,Command which the $result{data} will be piped to,can be overrided
108 # $result{hook} : Hook action,function process_data will be called
109 # $result{no_subdir} : Do not create sub directories
110 # $result{pass_data} : Data array which will be passed to next level of urlrule
111 # $result{pass_name} : Names of each $result{pass_data}
112 # $result{pass_arg} : Additional arguments to be passed to next level of urlrule
113 # urlrule_quick_parse($url,$rule,$data_exp,$data_map,$pass_exp,$pass_map,$charset)
114 # urlrule_parse_data($url,$rule,$data_exp,$data_map,$charset)
115 # urlrule_parse_pass_data($url,$rule,$pass_exp,$pass_map,$charset)
117 # $result{same_level} : Keep same rule level for passing down
118 # $result{level} : Specify rule level for passing down
119 #================================================================
127 if(-f
"$source" and ! -x
"$source") {