File Coverage

blib/lib/Rubric/Link.pm
Criterion Covered Total %
statement 27 31 87.1
branch 2 6 33.3
condition n/a
subroutine 9 9 100.0
pod 3 3 100.0
total 41 49 83.6


line stmt bran cond sub pod time code
1 12     12   10016 use strict;
  12         24  
  12         319  
2 12     12   50 use warnings;
  12         17  
  12         451  
3             # ABSTRACT: a link (URI) against which entries have been made
4              
5             #pod =head1 DESCRIPTION
6             #pod
7             #pod This class provides an interface to links in the Rubric. It inherits from
8             #pod Rubric::DBI, which is a Class::DBI class.
9             #pod
10             #pod =cut
11              
12             use base qw(Rubric::DBI);
13 12     12   58  
  12         20  
  12         1799  
14             use Digest::MD5 qw(md5_hex);
15 12     12   67  
  12         18  
  12         4077  
16             __PACKAGE__->table('links');
17              
18             #pod =head1 COLUMNS
19             #pod
20             #pod id - a unique identifier
21             #pod uri - the link itself
22             #pod md5 - the hex md5sum of the link's URI (set automatically)
23             #pod
24             #pod =cut
25              
26             __PACKAGE__->columns(All => qw(id uri md5));
27              
28             __PACKAGE__->add_constraint('scheme', uri => \&_check_schema);
29             my ($uri) = @_;
30             return 1 unless $uri;
31 5     5   5190 return 1 unless Rubric::Config->allowed_schemes;
32 5 50       16 $uri = URI->new($uri) unless ref $uri;
33 5 50       34 return scalar grep { $_ eq $uri->scheme } @{ Rubric::Config->allowed_schemes }
34 0 0       0 }
35 0         0  
  0         0  
  0         0  
36             #pod =head1 RELATIONSHIPS
37             #pod
38             #pod =head2 entries
39             #pod
40             #pod Every link has_many Rubric::Entries, available with the normal methods,
41             #pod including C<entries>.
42             #pod
43             #pod =cut
44              
45             __PACKAGE__->has_many(entries => 'Rubric::Entry');
46              
47             #pod =head3 entry_count
48             #pod
49             #pod This method returns the number of entries that refer to this link.
50             #pod
51             #pod =cut
52              
53             __PACKAGE__->set_sql(
54             entry_count => "SELECT COUNT(*) FROM entries WHERE link = ?"
55             );
56              
57             my ($self) = @_;
58             my $sth = $self->sql_entry_count;
59             $sth->execute($self->id);
60 93     93 1 17508 $sth->fetchall_arrayref->[0][0];
61 93         400 }
62 93         16616  
63 93         20848 #pod =head3 tags_counted
64             #pod
65             #pod This returns an arrayref of arrayrefs, each containing a tag name and the
66             #pod number of entries for this link tagged with that tag. The pairs are sorted in
67             #pod colation order by tag name.
68             #pod
69             #pod =cut
70              
71             __PACKAGE__->set_sql(tags_counted => <<'' );
72             SELECT DISTINCT tag, COUNT(*) AS count
73             FROM entrytags
74             WHERE entry IN (SELECT id FROM entries WHERE link = ?)
75             GROUP BY tag
76             ORDER BY tag
77              
78             my ($self) = @_;
79             my $sth = $self->sql_tags_counted;
80             $sth->execute($self->id);
81             my $tags = $sth->fetchall_arrayref;
82 2     2 1 6 return $tags;
83 2         13 }
84 2         1055  
85 2         792 #pod =head1 INFLATIONS
86 2         17 #pod
87             #pod =head2 uri
88             #pod
89             #pod The uri column inflates to a URI object.
90             #pod
91             #pod =cut
92              
93             __PACKAGE__->has_a(
94             uri => 'URI',
95             deflate => sub { (shift)->canonical->as_string }
96             );
97              
98             #pod =head1 METHODS
99             #pod
100             #pod =head2 stringify_self
101             #pod
102             #pod This method returns the link's URI as a string, and is teh default
103             #pod stringification for Rubric::Link objects.
104             #pod
105             #pod =cut
106              
107              
108             __PACKAGE__->add_trigger(before_create => \&_set_md5);
109              
110             my ($self) = @_;
111 561     561 1 178775 $self->_attribute_store(md5 => md5_hex("$self->{uri}"));
112             }
113              
114             1;
115              
116 6     6   1100  
117 6         51 =pod
118              
119             =encoding UTF-8
120              
121             =head1 NAME
122              
123             Rubric::Link - a link (URI) against which entries have been made
124              
125             =head1 VERSION
126              
127             version 0.157
128              
129             =head1 DESCRIPTION
130              
131             This class provides an interface to links in the Rubric. It inherits from
132             Rubric::DBI, which is a Class::DBI class.
133              
134             =head1 PERL VERSION
135              
136             This code is effectively abandonware. Although releases will sometimes be made
137             to update contact info or to fix packaging flaws, bug reports will mostly be
138             ignored. Feature requests are even more likely to be ignored. (If someone
139             takes up maintenance of this code, they will presumably remove this notice.)
140             This means that whatever version of perl is currently required is unlikely to
141             change -- but also that it might change at any new maintainer's whim.
142              
143             =head1 COLUMNS
144              
145             id - a unique identifier
146             uri - the link itself
147             md5 - the hex md5sum of the link's URI (set automatically)
148              
149             =head1 RELATIONSHIPS
150              
151             =head2 entries
152              
153             Every link has_many Rubric::Entries, available with the normal methods,
154             including C<entries>.
155              
156             =head3 entry_count
157              
158             This method returns the number of entries that refer to this link.
159              
160             =head3 tags_counted
161              
162             This returns an arrayref of arrayrefs, each containing a tag name and the
163             number of entries for this link tagged with that tag. The pairs are sorted in
164             colation order by tag name.
165              
166             =head1 INFLATIONS
167              
168             =head2 uri
169              
170             The uri column inflates to a URI object.
171              
172             =head1 METHODS
173              
174             =head2 stringify_self
175              
176             This method returns the link's URI as a string, and is teh default
177             stringification for Rubric::Link objects.
178              
179             =head1 AUTHOR
180              
181             Ricardo SIGNES <rjbs@semiotic.systems>
182              
183             =head1 COPYRIGHT AND LICENSE
184              
185             This software is copyright (c) 2004 by Ricardo SIGNES.
186              
187             This is free software; you can redistribute it and/or modify it under
188             the same terms as the Perl 5 programming language system itself.
189              
190             =cut