/[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 171 by dpavlin, Wed Jul 4 14:10:43 2007 UTC
# Line 83  sub _set { Line 83  sub _set {
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    

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

  ViewVC Help
Powered by ViewVC 1.1.26