blib/lib/KinoSearch1/Util/Class.pm

filter: Statementstmt 97.6% 83 / 85 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 95.8% 23 / 24 Podpod 100% 9 / 9 totaltotal 92.4% 123 / 133 CC 10 SCAR 7.6
CC
10
Cov
93%
new
5.1
_traverse_at_isa
4.0
ready_get
2.0
CRAP 2.1
« blib/lib/KinoSearch1/Highlight/SimpleHTMLEncoder.pm ↑ Summary blib/lib/KinoSearch1/Search/BooleanQuery.pm »
1 package KinoSearch1::Util::Class;
2 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 50 ▶use KinoSearch1::Util::ToolSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 50 ▶use KinoSearch1::Util::VerifyArgs qw( verify_args kerror );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5895 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod documented
9 5895 my $class = shift; # leave the rest of @_ intact.
10  
11 # find a defaults hash and verify args
12 5895 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
058950
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
13 5895 my $defaults;
14 {
15 50 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5895 $defaults = \%{ $class . '::instance_vars' };
17 }
18 5895 ▶ if ( !verify_args( $defaults, @_ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (verify_args($defaults, @_)) 1 5894 5895
19 # if a user-based subclass, find KinoSearch1 parent class and verify.
20 1 my $kinoclass = _traverse_at_isa($class);
21 1 ▶ confess kerror() unless $kinoclass;
Branch: 1 branch
BranchTrueFalseTotal
unless $kinoclass 0 1 1
22 {
23 50 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 $defaults = \%{ $kinoclass . '::instance_vars' };
25 }
26 1 ▶ confess kerror() unless verify_args( $defaults, @_ );
Branch: 1 branch
BranchTrueFalseTotal
unless verify_args($defaults, @_) 0 1 1
27 }
28  
29 # merge var => val pairs into new object, call customizable init routine
30 5895 my $self = bless { %$defaults, @_ }, $class;
31 5895 $self->init_instance;
32  
33 5894 return $self;
34 }
35  
36 # Walk @ISA until a parent class starting with 'KinoSearch1::' is found.
37 2 ▶sub _traverse_at_isa {
Subroutine _traverse_at_isa: called CC=4 SCAR=13.9
38 2 my $orig = shift;
39 {
40 50 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 my $at_isa = \@{ $orig . '::ISA' };
42 2 for my $parent (@$at_isa) {
43 2 ▶ return $parent if $parent =~ /^KinoSearch1::/;
Branch: 1 branch
BranchTrueFalseTotal
if $parent =~ /^KinoSearch1::/ 1 1 2
44 1 my $grand_parent = _traverse_at_isa($parent);
45 1 ▶ return $grand_parent if $grand_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $grand_parent 0 1 1
46 }
47 };
48 1 return '';
49 }
50  
51 1401 ▶sub init_instance { }
Subroutine init_instance: called CC=1 SCAR=0.0
Pod documented
52  
53 1875 ▶sub init_instance_vars {
Subroutine init_instance_vars: called CC=1 SCAR=0.0
Pod documented
54 1875 my $package = shift;
55  
56 50 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
57 50 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1875 my $first_isa = ${ $package . '::ISA' }[0];
59 1875 %{ $package . '::instance_vars' }
60 1875 = ( %{ $first_isa . '::instance_vars' }, @_ );
61 }
62  
63 244 ▶sub ready_get_set {
Subroutine ready_get_set: called CC=1 SCAR=0.0
Pod documented
64 244 ready_get(@_);
65 244 ready_set(@_);
66 }
67  
68 533 ▶sub ready_get {
Subroutine ready_get: called CC=2 SCAR=6.9
Pod documented
69 533 my $package = shift;
70 50 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 533 for my $member (@_) {
72 1462 ▶ *{ $package . "::get_$member" } = sub { return $_[0]->{$member} };
Subroutine __ANON__: called CC=1 SCAR=0.0
73 }
74 }
75  
76 244 ▶sub ready_set {
Subroutine ready_set: called CC=2 SCAR=6.9
Pod documented
77 244 my $package = shift;
78 50 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
79 244 for my $member (@_) {
80 841 ▶ *{ $package . "::set_$member" } = sub { $_[0]->{$member} = $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
81 }
82 }
83  
84 =for Rationale:
85 KinoSearch1 is not thread-safe. Among other things, the C-struct-based classes
86 cause segfaults or bus errors when their data gets double-freed by DESTROY.
87 Therefore, CLONE dies with a user-friendly error message before that happens.
88  
89 =cut
90  
91 0 ▶sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
92 0 my $package = shift;
93 0 die( "CLONE invoked by package '$package', indicating that threads "
94 . "or Win32 fork were initiated, but KinoSearch1 is not thread-safe"
95 );
96 }
97  
98 1 ▶sub abstract_death {
Subroutine abstract_death: called CC=1 SCAR=0.0
Pod documented
99 1 my ( undef, $filename, $line, $methodname ) = caller(1);
100 1 die "ERROR: $methodname', called at $filename line $line, is an "
101 . "abstract method and must be defined in a subclass";
102 }
103  
104 1 ▶sub unimplemented_death {
Subroutine unimplemented_death: called CC=1 SCAR=0.0
Pod documented
105 1 my ( undef, $filename, $line, $methodname ) = caller(1);
106 1 die "ERROR: $methodname, called at $filename line $line, is "
107 . "intentionally unimplemented in KinoSearch1, though it is part "
108 . "of Lucene";
109 }
110  
111 1 ▶sub todo_death {
Subroutine todo_death: called CC=1 SCAR=0.0
Pod documented
112 1 my ( undef, $filename, $line, $methodname ) = caller(1);
113 1 die "ERROR: $methodname, called at $filename line $line, is not "
114 . "implemented yet in KinoSearch1, but is on the todo list";
115 }
116  
117 50 1;
118  
119 __END__
« blib/lib/KinoSearch1/Highlight/SimpleHTMLEncoder.pm ↑ Summary blib/lib/KinoSearch1/Search/BooleanQuery.pm »