blib/lib/Smolder/DB/Preference.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
create
2.0
project
2.0
email_types
2.0
CRAP 2.0
1 package Smolder::DB::Preference;
2 use strict;
3 use warnings;
4 use base 'Smolder::DB';
5 use Smolder::DB::Project;
6  
7 __PACKAGE__->set_up_table('preference');
8  
9 __PACKAGE__->has_a(
10 email_sent_timestamp => 'DateTime',
11 inflate => sub { __PACKAGE__->parse_datetime(shift) },
12 deflate => sub { __PACKAGE__->format_datetime(shift) },
13 );
14  
15 sub create {
16 my ($class, $args) = @_;
17 $args ||= {
18 email_type => 'full',
19 email_freq => 'on_new',
20 };
21 return $class->SUPER::create($args);
22 }
23  
24 =head1 NAME
25  
26 Smolder::DB::Preference
27  
28 =head1 DESCRIPTION
29  
30 L<Class::DBI> based model class for the 'preference' table in the database.
31  
32 =head1 METHODS
33  
34 =head2 ACCESSSOR/MUTATORS
35  
36 Each column in the borough table has a method with the same name
37 that can be used as an accessor and mutator.
38  
39 =head2 OBJECT METHODS
40  
41 =head3 project
42  
43 If this Preference is associated with a project, then this will return
44 that L<Smolder::DB::Project> object, else it will return C<undef>.
45  
46 =cut
47  
48 sub project {
49 my $self = shift;
50 my $sql = q(
51 SELECT project.* FROM project, project_developer
52 WHERE project.id = project_developer.project
53 AND project_developer.preference = ?
54 );
55 my $sth = $self->db_Main->prepare_cached($sql);
56 $sth->execute($self->id);
57 my @projs = Smolder::DB::Project->sth_to_objects($sth);
58 return $projs[0];
59 }
60  
61 =head2 CLASS METHODS
62  
63 =head3 email_types
64  
65 Returns an arrayref of all acceptable values for the C<email_type> field.
66  
67 =cut
68  
69 sub email_types {
70 my $class = shift;
71 return $class->enum_values('email_type');
72 }
73  
74 =head3 email_freqs
75  
76 Returns an arrayref of all acceptable values for the C<email_freq> field.
77  
78 =cut
79  
80 sub email_freqs {
81 my $class = shift;
82 return $class->enum_values('email_freq');
83 }
84  
85 1;
86