line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
use strict; |
2
|
2
|
|
|
2
|
|
1078
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
76
|
|
3
|
2
|
|
|
2
|
|
10
|
use utf8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
40
|
|
4
|
2
|
|
|
2
|
|
8
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
our @EXPORT = qw/find_or_create/; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my ($self, $table, $args) = @_; |
8
|
|
|
|
|
|
|
my $row = $self->single($table, $args); |
9
|
5
|
|
|
5
|
1
|
4575
|
return $row if $row; |
10
|
5
|
|
|
|
|
22
|
$self->insert($table, $args)->refetch; |
11
|
5
|
100
|
|
|
|
19
|
} |
12
|
3
|
|
|
|
|
14
|
|
13
|
|
|
|
|
|
|
1; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Teng::Plugin::FindOrCreate - provide find_or_create method for your Teng class. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package MyDB; |
23
|
|
|
|
|
|
|
use parent qw/Teng/; |
24
|
|
|
|
|
|
|
__PACKAGE__->load_plugin('FindOrCreate'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package main; |
27
|
|
|
|
|
|
|
my $db = MyDB->new(...); |
28
|
|
|
|
|
|
|
my $row = $db->find_or_create('user',{name => 'lestrrat'}); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This plugin provides find_or_create method. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over 4 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item $row = $db->find_or_create($table[, \%args]]) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
I<$table> table name for counting |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
I<\%args> : HashRef for row data. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=back |