blib/lib/Teng/Plugin/TmpSuppressRowObjects.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 97.4% 38 / 39 CC 2 SCAR 2.5
CC
2
Cov
100%
search_by_sql_hashref
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
↑ Summary Build »
1 package Teng::Plugin::TmpSuppressRowObjects;
2 8 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 our $VERSION = "0.03";
7  
8 8 our @EXPORT;
9  
10 {
11 8 my @origs = qw(
12 insert
13 single
14 single_by_sql
15 single_named
16 search
17 search_named
18 );
19 8 my $suffix = '_hashref';
20  
21 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 for my $orig (@origs) {
23 48 my $method = $orig . $suffix;
24 48 push @EXPORT, $method;
25 48 *{__PACKAGE__ . '::' . $method} = sub {
26 8 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
27 8 local $self->{suppress_row_objects} = 1;
28 8 $self->$orig(@_);
29 48 };
30 }
31 8 push @EXPORT, qw(
32 search_by_sql_hashref
33 );
34 }
35  
36 sub search_by_sql_hashref {
37 2 ▶ my ($self, $sql, $bind, $table_name) = @_;
Subroutine search_by_sql_hashref: called CC=2 SCAR=6.9
Pod undocumented
38  
39 2 ▶ wantarray and return $self->dbh->selectall_array($sql, +{ Slice => +{} }, @$bind);
Branch: 1 branch
BranchTrueFalseTotal
wantarray and return $self->dbh->selectall_array($sql, {"Slice", {}}, @$bind) 1 1 2
40 1 local $self->{suppress_row_objects} = 1;
41 1 $self->search_by_sql($sql, $bind, $table_name);
42 }
43  
44  
45 8 1;
46 __END__
47  
48 =encoding utf-8
49  
50 =head1 NAME
51  
52 Teng::Plugin::TmpSuppressRowObjects - add methods with temporaly use of suppress_row_objects
53  
54 =head1 SYNOPSIS
55  
56 # In your Model ...
57 package Your::Model;
58 use parent qw(Teng);
59  
60 __PACKAGE__->load_plugin('TmpSuppressRowObjects');
61  
62  
63 # In case suppress_row_objects = 0 ...
64 my $teng = Your::Model->new(dbh => $dbh, suppress_row_objects => 0);
65 my @rows;
66  
67 # same usage with original 'search'
68 @rows = $teng->search_hashref(test_table => +{ id => 100 }); # elements in @rows are hashref
69  
70 # does not affect original 'search'
71 @rows = $teng->search(test_table => +{ id => 100 }); # elements in @rows are row object
72  
73  
74 =head1 DESCRIPTION
75  
76 This plugin adds some methods, which return hashref as a result, rather than row objects, even when C<suppress_row_objects> is 0.
77 It is useful when we want row objects as default, and lightweight hashref in some cases to improve performance.
78  
79  
80 =head1 METHODS
81  
82 insert_hashref
83 search_hashref
84 single_hashref
85 search_by_sql_hashref
86 single_by_sql_hashref
87 search_named_hashref
88 single_named_hashref
89  
90 Usage of those methods are the same to original methods (without C<_hashref>).
91  
92  
93 =head1 LICENSE
94  
95 Copyright (C) egawata.
96  
97 This library is free software; you can redistribute it and/or modify
98 it under the same terms as Perl itself.
99  
100 =head1 AUTHOR
101  
102 egawata E<lt>egawa.takashi@gmail.comE<gt>
103  
104 =cut
105  
↑ Summary Build »