Ignore:
Timestamp:
May 10, 2003, 6:31:23 PM (19 years ago)
Author:
kake
Message:

PubCrawl?.pm now uses CGI::Wiki::Plugin::Categoriser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/UK/PubCrawl.pm

    r113 r114  
    2929
    3030  my $wiki = CGI::Wiki->new( ... );
    31   my $locator = CGI::Wiki::Locator::UK->new;
     31  my $locator = CGI::Wiki::Plugin::Locator::UK->new;
    3232  $wiki->register_plugin( plugin => $locator );
    33   my $crawler = OpenGuides::UK::PubCrawl->new( locator => $locator );
     33  my $categoriser = CGI::Wiki::Plugin::Categoriser->new;
     34  $wiki->register_plugin( plugin => $categoriser );
     35
     36  my $crawler = OpenGuides::UK::PubCrawl->new(
     37      locator     => $locator,
     38      categoriser => $categoriser );
    3439  $wiki->register_plugin( plugin => $crawler );
    3540 
     
    4045=item B<new>
    4146
     47  my $crawler = OpenGuides::UK::PubCrawl->new(
     48      locator     => $locator,
     49      categoriser => $categoriser );
     50
    4251  my $crawler = OpenGuides::UK::PubCrawl->new( locator => $locator );
    4352
    44 Croaks unless a C<CGI::Wiki::Plugin::Locator::UK> object is supplied.
     53Croaks unless a C<CGI::Wiki::Plugin::Locator::UK> object and a
     54C<CGI::Wiki::Plugin::Categoriser> object are supplied.
    4555
    4656=cut
     
    4858sub new {
    4959    my ($class, %args) = @_;
    50     my $locator = $args{locator} or croak "No locator parameter supplied";
    51     croak "Locator paramater is not a CGI::Wiki::Plugin::Locator::UK"
     60    my $locator = $args{locator}
     61      or croak "No locator parameter supplied";
     62    croak "Locator parameter is not a CGI::Wiki::Plugin::Locator::UK"
    5263      unless UNIVERSAL::isa( $locator, "CGI::Wiki::Plugin::Locator::UK" );
    53     my $self = { _locator => $locator };
     64    my $categoriser = $args{categoriser}
     65      or croak "No categoriser parameter supplied";
     66    croak "Categoriser parameter is not a CGI::Wiki::Plugin::Categoriser"
     67      unless UNIVERSAL::isa( $categoriser, "CGI::Wiki::Plugin::Categoriser" );
     68    my $self = { _locator     => $locator,
     69                 _categoriser => $categoriser };
    5470    bless $self, $class;
    5571    return $self;
     
    6783}
    6884
     85=item B<categoriser>
     86
     87Returns categoriser object.
     88
     89=cut
     90
     91sub categoriser {
     92    my $self = shift;
     93    return $self->{_categoriser};
     94}
     95
    6996=item B<generate_crawl>
    7097
     
    78105
    79106These are the only options so far.  Returns an array of nodenames.
    80 C<num_pubs> will default to 5, for the sake of your liver.
     107C<num_pubs> will default to 5, for the sake of your liver.  If it
     108can't find a crawl as long as you asked for, returns the longest one
     109it could find.
    81110
    82111=cut
     
    89118    my $num_pubs = $args{num_pubs} || 5;
    90119    my $locator = $self->locator;
     120    my $categoriser = $self->categoriser;
    91121    my @firsts = $locator->find_within_distance( os_x       => $x,
    92122                                                 os_y       => $y,
     
    94124    my %omit = map { $_ => 1 } @{ $args{omit} || [] };
    95125    @firsts = grep { !$omit{$_}
    96                      and $self->_in_category( category => "Pubs",
    97                                               node     => $_      )
     126                     and $categoriser->in_category( category => "Pubs",
     127                                                    node     => $_      )
    98128                   } @firsts;
    99129    return () unless scalar @firsts;
     
    124154}
    125155
    126 # $self->_in_category( category => "Pubs",
    127 #                      node     => "Cittie Of Yorke" );
    128 #
    129 # Returns true if node is in category, false otherwise.
    130 sub _in_category {
    131     my ($self, %args) = @_;
    132     my $dbh = $self->datastore->dbh;
    133     my $sth = $dbh->prepare( "
    134 SELECT metadata.metadata_value FROM metadata, node WHERE node.name = ? AND metadata.node = node.name AND metadata.version = node.version AND metadata.metadata_type = 'category'
    135     " );
    136     $sth->execute( $args{node} );
    137     my %categories;
    138     while ( my ($cat) = $sth->fetchrow_array ) {
    139         $categories{$cat} = 1;
    140     }
    141     return $categories{$args{category}};
    142 }
    143 
    144156=back
    145157
Note: See TracChangeset for help on using the changeset viewer.