/[Grep]/lib/Grep/Model/Item.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Grep/Model/Item.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 170 by dpavlin, Wed Jul 4 12:52:50 2007 UTC revision 178 by dpavlin, Mon Sep 3 16:05:38 2007 UTC
# Line 10  use Grep::Record schema { Line 10  use Grep::Record schema {
10    
11          column in_feed =>          column in_feed =>
12                  refers_to Grep::Model::Feed by 'id',                  refers_to Grep::Model::Feed by 'id',
13                    is indexed,
14                  is mandatory;                  is mandatory;
15                    
16          column title =>          column title =>
# Line 18  use Grep::Record schema { Line 19  use Grep::Record schema {
19                    
20          column link =>          column link =>
21                  type is 'text',                  type is 'text',
22                    is distinct,
23                    is indexed,
24                  is mandatory;                  is mandatory;
25                    
26          column content =>          column content =>
# Line 83  sub _set { Line 86  sub _set {
86          return ($val, $msg);          return ($val, $msg);
87  }  }
88    
89    =head2 link_current
90    
91      my $item = Grep::Model::Item->link_currnet( 'http://www.example.com' )
92      my $item = $item->link_current( 'http://www.example.com' );
93    
94    =cut
95    
96    my $update_every_hr = 24; # s
97    
98    sub link_current {
99            my $self = shift;
100            my $uri = shift || die "no uri?";
101    
102            my $item = $self;
103            if ( ! ref($self) || ! $self->link || ( $self->link && $self->link ne $uri ) ) {
104                    $item = Grep::Model::Item->new;
105                    #warn "load_by_cols link => $uri";
106                    $item->load_by_cols( link => $uri );
107                    return $item if $item->id;
108                    return 0;
109            }
110    
111            return 0 unless ( $item );
112    
113            die "item is not Grep::Model::Item, but ", ref( $item ) unless ref( $item ) eq 'Grep::Model::Item';
114    
115            my $last_update = $item->last_update || $item->created_on; # fallback
116            return 0 unless defined( $last_update ) && $last_update;
117    
118            my $newer_than = DateTime->now->subtract( hours => $update_every_hr );
119            #warn "$last_update > $newer_than";
120            return 0 if ( $last_update - $newer_than )->is_negative;
121            return $item;
122    }
123    
124  1;  1;
125    

Legend:
Removed from v.170  
changed lines
  Added in v.178

  ViewVC Help
Powered by ViewVC 1.1.26