| Rubric documentation | Contained in the Rubric distribution. |
Rubric::Link - a link (URI) against which entries have been made
version 0.147
This class provides an interface to links in the Rubric. It inherits from Rubric::DBI, which is a Class::DBI class.
id - a unique identifier uri - the link itself md5 - the hex md5sum of the link's URI (set automatically)
Every link has_many Rubric::Entries, available with the normal methods,
including entries.
This method returns the number of entries that refer to this link.
The uri column inflates to a URI object.
This method returns the link's URI as a string, and is teh default stringification for Rubric::Link objects.
Ricardo SIGNES, <rjbs@cpan.org>
Please report any bugs or feature requests to bug-rubric@rt.cpan.org, or
through the web interface at http://rt.cpan.org. I will be notified, and
then you'll automatically be notified of progress on your bug as I make
changes.
Copyright 2004 Ricardo SIGNES. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Rubric documentation | Contained in the Rubric distribution. |
use strict; use warnings; package Rubric::Link; our $VERSION = '0.147';
use base qw(Rubric::DBI); use Digest::MD5 qw(md5_hex); __PACKAGE__->table('links');
__PACKAGE__->columns(All => qw(id uri md5)); __PACKAGE__->add_constraint('scheme', uri => \&_check_schema); sub _check_schema { my ($uri) = @_; return 1 unless $uri; return 1 unless Rubric::Config->allowed_schemes; $uri = URI->new($uri) unless ref $uri; return scalar grep { $_ eq $uri->scheme } @{ Rubric::Config->allowed_schemes } }
__PACKAGE__->has_many(entries => 'Rubric::Entry');
__PACKAGE__->set_sql( entry_count => "SELECT COUNT(*) FROM entries WHERE link = ?" ); sub entry_count { my ($self) = @_; my $sth = $self->sql_entry_count; $sth->execute($self->id); $sth->fetchall_arrayref->[0][0]; }
__PACKAGE__->set_sql(tags_counted => <<'' ); SELECT DISTINCT tag, COUNT(*) AS count FROM entrytags WHERE entry IN (SELECT id FROM entries WHERE link = ?) GROUP BY tag ORDER BY tag sub tags_counted { my ($self) = @_; my $sth = $self->sql_tags_counted; $sth->execute($self->id); my $tags = $sth->fetchall_arrayref; return $tags; }
__PACKAGE__->has_a( uri => 'URI', deflate => sub { (shift)->canonical->as_string } );
sub stringify_self { $_[0]->uri->as_string } __PACKAGE__->add_trigger(before_create => \&_set_md5); sub _set_md5 { my ($self) = @_; $self->_attribute_store(md5 => md5_hex("$self->{uri}")); }
1;