| 1 | |||||||||||||||||||||
| 2 | package MyConText::String; | ||||||||||||||||||||
| 3 | 1 | ▶ | use MyConText; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use vars qw! @ISA !; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | @ISA = qw! MyConText !; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | # Create creates the conversion table that converts string names of | ||||||||||||||||||||
| 9 | # documents to numbers | ||||||||||||||||||||
| 10 | 0 | ▶ | sub _create_tables { | ||||||||||||||||||
|
Subroutine
_create_tables: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 11 | 0 | my $ctx = shift; | |||||||||||||||||||
| 12 | $ctx->{'doc_id_table'} = $ctx->{'table'} . '_docid' | ||||||||||||||||||||
| 13 | 0 | ▶ | unless defined $ctx->{'doc_id_table'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 0 | my $CREATE_DOCID = <<EOF; | |||||||||||||||||||
| 16 | create table $ctx->{'doc_id_table'} ( | ||||||||||||||||||||
| 17 | name varchar($ctx->{'name_length'}) binary not null, | ||||||||||||||||||||
| 18 | id $MyConText::BITS_TO_INT{$ctx->{'doc_id_bits'}} unsigned not null auto_increment, | ||||||||||||||||||||
| 19 | primary key (id), | ||||||||||||||||||||
| 20 | unique (name) | ||||||||||||||||||||
| 21 | ) | ||||||||||||||||||||
| 22 | EOF | ||||||||||||||||||||
| 23 | 0 | my $dbh = $ctx->{'dbh'}; | |||||||||||||||||||
| 24 | 0 | ▶ | $dbh->do($CREATE_DOCID) or return $dbh->errstr; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 0 | push @{$ctx->{'created_tables'}}, $ctx->{'doc_id_table'}; | |||||||||||||||||||
| 26 | 0 | return; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | ▶ | sub get_id_for_name { | ||||||||||||||||||
|
Subroutine
get_id_for_name: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 30 | 0 | my ($self, $string) = @_; | |||||||||||||||||||
| 31 | 0 | my $dbh = $self->{'dbh'}; | |||||||||||||||||||
| 32 | 0 | my $doc_id_table = $self->{'doc_id_table'}; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | my $name_to_id_sth = ( defined $self->{'name_to_id_sth'} | ||||||||||||||||||||
| 35 | ? $self->{'name_to_id_sth'} | ||||||||||||||||||||
| 36 | 0 | ▶ | : $self->{'name_to_id_sth'} = $dbh->prepare("select id from $doc_id_table where name = ?") or die $dbh->errstr); | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
(defined $self->{'name_to_id_sth'} ? $self->{'name_to_id_sth'} : $self->{'name_to_id_sth'} = $dbh->prepare("select id from $doc_id_table where name = ?")) || die($dbh->errstr)
MC/DC0%0/1
(defined $self->{'name_to_id_sth'} ? $self->{'name_to_id_sth'} : $self->{'name_to_id_sth'} = $dbh->prepare("select id from $doc_id_table where name = ?")) || die($dbh->errstr)
(defined $self->{'name_to_id_sth'} ? $self->{'name_to_id_sth'} : $self->{'name_to_id_sth'} = $dbh->prepare("select id from $doc_id_table where name = ?"))
Truth table0%0/2
A
A= (defined $self->{'name_to_id_sth'} ? $self->{'name_to_id_sth'} : $self->{'name_to_id_sth'} = $dbh->prepare("select id from $doc_id_table where name = ?"))
| |||||||||||||||||||||
| 37 | 0 | my $id = $dbh->selectrow_array($name_to_id_sth, {}, $string); | |||||||||||||||||||
| 38 | 0 | ▶ | if (not defined $id) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | my $new_name_sth = (defined $self->{'new_name_sth'} | ||||||||||||||||||||
| 40 | ? $self->{'new_name_sth'} | ||||||||||||||||||||
| 41 | 0 | ▶ | : $self->{'new_name_sth'} = | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
(defined $self->{'new_name_sth'} ? $self->{'new_name_sth'} : $self->{'new_name_sth'} = $dbh->prepare("insert into $doc_id_table values (?, null)")) || die($dbh->errstr)
MC/DC0%0/1
(defined $self->{'new_name_sth'} ? $self->{'new_name_sth'} : $self->{'new_name_sth'} = $dbh->prepare("insert into $doc_id_table values (?, null)")) || die($dbh->errstr)
(defined $self->{'new_name_sth'} ? $self->{'new_name_sth'} : $self->{'new_name_sth'} = $dbh->prepare("insert into $doc_id_table values (?, null)"))
Truth table0%0/2
A
A= (defined $self->{'new_name_sth'} ? $self->{'new_name_sth'} : $self->{'new_name_sth'} = $dbh->prepare("insert into $doc_id_table values (?, null)"))
| |||||||||||||||||||||
| 42 | $dbh->prepare("insert into $doc_id_table values (?, null)") or die $dbh->errstr ); | ||||||||||||||||||||
| 43 | 0 | ▶ | $new_name_sth->execute($string) or die $new_name_sth->errstr; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | $id = $new_name_sth->{'mysql_insertid'}; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 0 | $id; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 0 | ▶ | sub index_document { | ||||||||||||||||||
|
Subroutine
index_document: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 49 | 0 | my ($self, $string, $data) = @_; | |||||||||||||||||||
| 50 | 0 | my $id = $self->get_id_for_name($string); | |||||||||||||||||||
| 51 | 0 | $self->SUPER::index_document($id, $data); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | ▶ | sub contains_hashref { | ||||||||||||||||||
|
Subroutine
contains_hashref: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||
| 56 | 0 | my $res = $self->SUPER::contains_hashref(@_); | |||||||||||||||||||
| 57 | 0 | ▶ | return unless keys %$res; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | my $doc_id_table = $self->{'doc_id_table'}; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | my $data = $self->{'dbh'}->selectall_arrayref("select name, id from $doc_id_table where " . join(' or ', ('id = ?') x keys %$res), {}, keys %$res); | |||||||||||||||||||
| 62 | 0 | return { map { ( $_->[0], $res->{$_->[1]} ) } @$data }; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 1 | 1; | |||||||||||||||||||
| 67 | |||||||||||||||||||||