83 |
return ($val, $msg); |
return ($val, $msg); |
84 |
} |
} |
85 |
|
|
86 |
|
=head2 link_current |
87 |
|
|
88 |
|
my $item = Grep::Model::Item->link_currnet( 'http://www.example.com' ) |
89 |
|
my $item = $item->link_current( 'http://www.example.com' ); |
90 |
|
|
91 |
|
=cut |
92 |
|
|
93 |
|
my $update_every_hr = 24; # s |
94 |
|
|
95 |
|
sub link_current { |
96 |
|
my $self = shift; |
97 |
|
my $uri = shift || die "no uri?"; |
98 |
|
|
99 |
|
my $item = $self; |
100 |
|
if ( ! ref($self) || ! $self->link || ( $self->link && $self->link ne $uri ) ) { |
101 |
|
$item = Grep::Model::Item->new; |
102 |
|
#warn "load_by_cols link => $uri"; |
103 |
|
$item->load_by_cols( link => $uri ); |
104 |
|
return $item if $item->id; |
105 |
|
return 0; |
106 |
|
} |
107 |
|
|
108 |
|
return 0 unless ( $item ); |
109 |
|
|
110 |
|
die "item is not Grep::Model::Item, but ", ref( $item ) unless ref( $item ) eq 'Grep::Model::Item'; |
111 |
|
|
112 |
|
my $last_update = $item->last_update || $item->created_on; # fallback |
113 |
|
return 0 unless defined( $last_update ) && $last_update; |
114 |
|
|
115 |
|
my $newer_than = DateTime->now->subtract( hours => $update_every_hr ); |
116 |
|
#warn "$last_update > $newer_than"; |
117 |
|
return 0 if ( $last_update - $newer_than )->is_negative; |
118 |
|
return $item; |
119 |
|
} |
120 |
|
|
121 |
1; |
1; |
122 |
|
|