| 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.02"; | |
| 7 | |||
| 8 | 8 | our @EXPORT; | |
| 9 | |||
| 10 | { | ||
| 11 | 8 | my @origs = qw( | |
| 12 | insert | ||
| 13 | search | ||
| 14 | single | ||
| 15 | search_by_sql | ||
| 16 | single_by_sql | ||
| 17 | search_named | ||
| 18 | single_named | ||
| 19 | ); | ||
| 20 | 8 | my $suffix = '_hashref'; | |
| 21 | |||
| 22 | 8 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | 8 | for my $orig (@origs) { | |
| 24 | 56 | my $method = $orig . $suffix; | |
| 25 | 56 | push @EXPORT, $method; | |
| 26 | 56 | *{__PACKAGE__ . '::' . $method} = sub { | |
| 27 | 7 | ▶ | my $self = shift; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 28 | 7 | local $self->{suppress_row_objects} = 1; | |
| 29 | 7 | $self->$orig(@_); | |
| 30 | 56 | }; | |
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | 8 | 1; | |
| 35 | __END__ | ||
| 36 | |||
| 37 | =encoding utf-8 | ||
| 38 | |||
| 39 | =head1 NAME | ||
| 40 | |||
| 41 | Teng::Plugin::TmpSuppressRowObjects - add methods with temporary use of suppress_row_objects | ||
| 42 | |||
| 43 | =head1 SYNOPSIS | ||
| 44 | |||
| 45 | # In your Model ... | ||
| 46 | package Your::Model; | ||
| 47 | use parent qw(Teng); | ||
| 48 | |||
| 49 | __PACKAGE__->load_plugin('TmpSuppressRowObjects'); | ||
| 50 | |||
| 51 | |||
| 52 | # In case suppress_row_objects = 0 ... | ||
| 53 | my $teng = Your::Model->new(dbh => $dbh, suppress_row_objects => 0); | ||
| 54 | my $row; | ||
| 55 | |||
| 56 | # same usage with original 'search' | ||
| 57 | $row = $teng->search_hashref(test_table => +{ id => 100 }); # $row is hashref | ||
| 58 | |||
| 59 | # does not affect original 'search' | ||
| 60 | $row = $teng->search(test_table => +{ id => 100 }); # $row is row object | ||
| 61 | |||
| 62 | |||
| 63 | =head1 DESCRIPTION | ||
| 64 | |||
| 65 | This plugin adds some methods, which suppress generating row objects, even when C<suppress_row_objects> is 0. | ||
| 66 | It is helpful when we want to use row objects in default, but temporarily use hashref to improve performance. | ||
| 67 | |||
| 68 | |||
| 69 | =head1 METHODS | ||
| 70 | |||
| 71 | insert_hashref | ||
| 72 | search_hashref | ||
| 73 | single_hashref | ||
| 74 | search_by_sql_hashref | ||
| 75 | single_by_sql_hashref | ||
| 76 | search_named_hashref | ||
| 77 | single_named_hashref | ||
| 78 | |||
| 79 | Usage of those methods are the same to original methods (without C<_hashref>). | ||
| 80 | |||
| 81 | |||
| 82 | =head1 LICENSE | ||
| 83 | |||
| 84 | Copyright (C) egawata. | ||
| 85 | |||
| 86 | This library is free software; you can redistribute it and/or modify | ||
| 87 | it under the same terms as Perl itself. | ||
| 88 | |||
| 89 | =head1 AUTHOR | ||
| 90 | |||
| 91 | egawata E<lt>egawa.takashi@gmail.comE<gt> | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||