Filename | /mnt/catalyst/koha/C4/Linker.pm |
Statements | Executed 12 statements in 446µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 592µs | 608µs | BEGIN@45 | C4::Linker::
1 | 1 | 1 | 9µs | 42µs | BEGIN@47 | C4::Linker::
1 | 1 | 1 | 9µs | 78µs | BEGIN@50 | C4::Linker::
1 | 1 | 1 | 9µs | 11µs | BEGIN@48 | C4::Linker::
1 | 1 | 1 | 8µs | 15µs | BEGIN@46 | C4::Linker::
0 | 0 | 0 | 0s | 0s | _handle_auth_limit | C4::Linker::
0 | 0 | 0 | 0s | 0s | new | C4::Linker::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package C4::Linker; | ||||
2 | |||||
3 | # Copyright 2011 C & P Bibliography Services | ||||
4 | # | ||||
5 | # This file is part of Koha. | ||||
6 | # | ||||
7 | # Koha is free software; you can redistribute it and/or modify it under the | ||||
8 | # terms of the GNU General Public License as published by the Free Software | ||||
9 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
10 | # version. | ||||
11 | # | ||||
12 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
14 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
15 | # | ||||
16 | # You should have received a copy of the GNU General Public License along | ||||
17 | # with Koha; if not, write to the Free Software Foundation, Inc., | ||||
18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
19 | |||||
20 | =head1 NAME | ||||
21 | |||||
22 | C4::Linker - Base class for linking authorities to bibliographic records | ||||
23 | |||||
24 | =head1 SYNOPSIS | ||||
25 | |||||
26 | use C4::Linker (%params ); | ||||
27 | |||||
28 | =head1 DESCRIPTION | ||||
29 | |||||
30 | Base class for C4::Linker::X. Subclasses need to provide the following methods | ||||
31 | |||||
32 | B<get_link ($field)> - return the authid for the authority that should be | ||||
33 | linked to the provided MARC::Field object, and a boolean to indicate whether | ||||
34 | the match is "fuzzy" (the semantics of "fuzzy" are up to the individual plugin). | ||||
35 | In order to handle authority limits, get_link should always end with: | ||||
36 | return $self->SUPER::_handle_auth_limit($authid), $fuzzy; | ||||
37 | |||||
38 | B<flip_heading ($field)> - return a MARC::Field object with the heading flipped | ||||
39 | to the preferred form. | ||||
40 | |||||
41 | =head1 FUNCTIONS | ||||
42 | |||||
43 | =cut | ||||
44 | |||||
45 | 2 | 30µs | 2 | 623µs | # spent 608µs (592+15) within C4::Linker::BEGIN@45 which was called:
# once (592µs+15µs) by C4::Biblio::BEGIN@38 at line 45 # spent 608µs making 1 call to C4::Linker::BEGIN@45
# spent 15µs making 1 call to strict::import |
46 | 2 | 21µs | 2 | 22µs | # spent 15µs (8+7) within C4::Linker::BEGIN@46 which was called:
# once (8µs+7µs) by C4::Biblio::BEGIN@38 at line 46 # spent 15µs making 1 call to C4::Linker::BEGIN@46
# spent 7µs making 1 call to warnings::import |
47 | 2 | 24µs | 2 | 75µs | # spent 42µs (9+33) within C4::Linker::BEGIN@47 which was called:
# once (9µs+33µs) by C4::Biblio::BEGIN@38 at line 47 # spent 42µs making 1 call to C4::Linker::BEGIN@47
# spent 33µs making 1 call to Exporter::import |
48 | 2 | 24µs | 2 | 14µs | # spent 11µs (9+2) within C4::Linker::BEGIN@48 which was called:
# once (9µs+2µs) by C4::Biblio::BEGIN@38 at line 48 # spent 11µs making 1 call to C4::Linker::BEGIN@48
# spent 2µs making 1 call to C4::Context::import |
49 | |||||
50 | 2 | 336µs | 2 | 148µs | # spent 78µs (9+70) within C4::Linker::BEGIN@50 which was called:
# once (9µs+70µs) by C4::Biblio::BEGIN@38 at line 50 # spent 78µs making 1 call to C4::Linker::BEGIN@50
# spent 70µs making 1 call to base::import |
51 | |||||
52 | 1 | 7µs | 1 | 16µs | __PACKAGE__->mk_accessors(qw( )); # spent 16µs making 1 call to Class::Accessor::mk_accessors |
53 | |||||
54 | sub new { | ||||
55 | my $class = shift; | ||||
56 | my $param = shift; | ||||
57 | |||||
58 | my $self = {}; | ||||
59 | |||||
60 | while ( my ( $key, $value ) = each %$param ) { | ||||
61 | if ( $key eq 'auth_limit' && $value ) { | ||||
62 | my $dbh = C4::Context->dbh; | ||||
63 | my $sql = | ||||
64 | "SELECT authid FROM auth_header WHERE $value ORDER BY authid ASC"; | ||||
65 | my $sth = $dbh->prepare($sql); | ||||
66 | $sth->execute(); | ||||
67 | while ( my ($authid) = $sth->fetchrow_array() ) { | ||||
68 | push @{ $self->{'auths_to_link'} }, $authid; | ||||
69 | } | ||||
70 | } | ||||
71 | elsif ( $key eq 'options' && $value ) { | ||||
72 | foreach my $opt ( split( /\|/, $value ) ) { | ||||
73 | $self->{$opt} = 1; | ||||
74 | } | ||||
75 | } | ||||
76 | elsif ($value) { | ||||
77 | $self->{$key} = $value; | ||||
78 | } | ||||
79 | } | ||||
80 | |||||
81 | bless $self, $class; | ||||
82 | return $self; | ||||
83 | } | ||||
84 | |||||
85 | =head2 _handle_auth_limit | ||||
86 | |||||
87 | return $self->SUPER::_handle_auth_limit($authid), $fuzzy; | ||||
88 | |||||
89 | Function to be called by subclasses to handle authority record limits. | ||||
90 | |||||
91 | =cut | ||||
92 | |||||
93 | sub _handle_auth_limit { | ||||
94 | my $self = shift; | ||||
95 | my $authid = shift; | ||||
96 | |||||
97 | if ( defined $self->{'auths_to_link'} && defined $authid && !grep { $_ == $authid } | ||||
98 | @{ $self->{'auths_to_link'} } ) | ||||
99 | { | ||||
100 | undef $authid; | ||||
101 | } | ||||
102 | return $authid; | ||||
103 | } | ||||
104 | |||||
105 | =head2 EXPORT | ||||
106 | |||||
107 | None by default. | ||||
108 | |||||
109 | =head1 SEE ALSO | ||||
110 | |||||
111 | C4::Linker::Default | ||||
112 | |||||
113 | =head1 AUTHOR | ||||
114 | |||||
115 | Jared Camins-Esakov, C & P Bibliography Services, E<lt>jcamins@cpbibliography.comE<gt> | ||||
116 | |||||
117 | =cut | ||||
118 | |||||
119 | 1 | 3µs | 1; | ||
120 | |||||
121 | __END__ |