1 |
dpavlin |
2 |
use strict; |
2 |
|
|
use warnings; |
3 |
|
|
|
4 |
|
|
package Grep::Model::Feed; |
5 |
|
|
use Jifty::DBI::Schema; |
6 |
|
|
|
7 |
dpavlin |
19 |
use Feed::Find; |
8 |
|
|
|
9 |
dpavlin |
2 |
use Grep::Record schema { |
10 |
|
|
|
11 |
|
|
column uri => |
12 |
|
|
type is 'text', |
13 |
|
|
label is 'URI', |
14 |
dpavlin |
19 |
hints is 'Replace search string in URI with %s (grep will be replaced automatically)', |
15 |
dpavlin |
2 |
is mandatory, |
16 |
|
|
distinct; |
17 |
|
|
|
18 |
dpavlin |
3 |
column title => |
19 |
|
|
type is 'text', |
20 |
dpavlin |
19 |
label is 'Title', |
21 |
dpavlin |
12 |
hints is 'Use something descriptive to you', |
22 |
dpavlin |
3 |
since '0.0.2'; |
23 |
|
|
|
24 |
dpavlin |
19 |
column cookie => |
25 |
|
|
type is 'text', |
26 |
|
|
label is 'Cookie', |
27 |
|
|
render as 'textarea', |
28 |
|
|
hints are 'If you leave Cookie data Grep will impersonate you to feed provider!', |
29 |
|
|
since '0.0.3'; |
30 |
|
|
|
31 |
dpavlin |
2 |
}; |
32 |
|
|
|
33 |
dpavlin |
3 |
sub since { '0.0.1' } |
34 |
|
|
|
35 |
dpavlin |
2 |
# Your model-specific methods go here. |
36 |
|
|
|
37 |
dpavlin |
19 |
=head2 canonicalize_uri |
38 |
|
|
|
39 |
|
|
Replace C<grep>' with C<%s> in URI arguments |
40 |
|
|
|
41 |
|
|
=cut |
42 |
|
|
|
43 |
|
|
sub canonicalize_uri { |
44 |
|
|
my $self = shift; |
45 |
|
|
my $value = shift; |
46 |
|
|
warn "uri: $value"; |
47 |
|
|
$value =~ s/=grep/=%s/; |
48 |
|
|
return $value; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
=head2 search_uri |
52 |
|
|
|
53 |
|
|
print $feed->search_uri('search string'); |
54 |
|
|
|
55 |
|
|
This function will decode field delimiters C<|!|> into normal C<;> |
56 |
|
|
(which are protected to make AJAX validation work) |
57 |
|
|
|
58 |
|
|
=cut |
59 |
|
|
|
60 |
|
|
sub search_uri { |
61 |
|
|
my $self = shift; |
62 |
|
|
my $search = shift; |
63 |
|
|
|
64 |
|
|
my $uri = $self->uri or die "no uri?"; |
65 |
|
|
$uri =~ s/\Q|!|\E/;/g; |
66 |
|
|
return sprintf( $uri, $search ); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
|
70 |
dpavlin |
2 |
1; |
71 |
|
|
|