blib/lib/Teng/Plugin/FindOrCreate.pm untested

filter: Statementstmt 0.0% 0 / 15 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 22 CC 2 SCAR 12.8
CC
2
Cov
0%
find_or_create
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.6
1 package Teng::Plugin::FindOrCreate;
2 use strict;
3 use warnings;
4 use utf8;
5  
6 our @EXPORT = qw/find_or_create/;
7  
8 sub find_or_create {
9 my ($self, $table, $args) = @_;
10 my $row = $self->single($table, $args);
11 return $row if $row;
12 $self->insert($table, $args)->refetch;
13 }
14  
15 1;
16  
17 __END__
18  
19 =head1 NAME
20  
21 Teng::Plugin::FindOrCreate - provide find_or_create method for your Teng class.
22  
23 =head1 NAME
24  
25 package MyDB;
26 use parent qw/Teng/;
27 __PACKAGE__->load_plugin('FindOrCreate');
28  
29 package main;
30 my $db = MyDB->new(...);
31 my $row = $db->find_or_create('user',{name => 'lestrrat'});
32  
33 =head1 DESCRIPTION
34  
35 This plugin provides find_or_create method.
36  
37 =head1 METHODS
38  
39 =over 4
40  
41 =item $row = $db->find_or_create($table[, \%args]])
42  
43 I<$table> table name for counting
44  
45 I<\%args> : HashRef for row data.
46  
47 =back