File Coverage

blib/lib/FeyX/Active/Table.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package FeyX::Active::Table;
2 1     1   6672 use Moose;
  0            
  0            
3              
4             our $VERSION = '0.03';
5             our $AUTHORITY = 'cpan:STEVAN';
6              
7             use FeyX::Active::SQL::Select;
8             use FeyX::Active::SQL::Update;
9             use FeyX::Active::SQL::Insert;
10             use FeyX::Active::SQL::Delete;
11              
12             extends 'Fey::Table';
13              
14             sub select {
15             my $self = shift;
16             my $select = FeyX::Active::SQL::Select->new(
17             dbh => $self->schema->dbi_manager->default_source->dbh
18             );
19              
20             $select->from( $self );
21             $select->select( @_ ? @_ : $self );
22             $select;
23             }
24              
25             sub delete {
26             my $self = shift;
27             my $delete = FeyX::Active::SQL::Delete->new(
28             dbh => $self->schema->dbi_manager->default_source->dbh
29             );
30              
31             $delete->from( $self );
32             $delete;
33             }
34              
35             sub insert {
36             my $self = shift;
37             my $insert = FeyX::Active::SQL::Insert->new(
38             dbh => $self->schema->dbi_manager->default_source->dbh
39             );
40              
41             $insert->into( $self );
42             $insert->values( @_ ) if @_;
43             $insert;
44             }
45              
46             sub update {
47             my $self = shift;
48             my $update = FeyX::Active::SQL::Update->new(
49             dbh => $self->schema->dbi_manager->default_source->dbh
50             );
51              
52             $update->update( $self );
53             $update->set( @_ ) if @_;
54             $update;
55             }
56              
57             __PACKAGE__->meta->make_immutable;
58              
59             no Moose; 1;
60              
61             __END__
62              
63             =pod
64              
65             =head1 NAME
66              
67             FeyX::Active::Table - An active Fey Table
68              
69             =head1 SYNOPSIS
70              
71             use FeyX::Active::Table;
72              
73             my $Person = FeyX::Active::Table->new(name => 'Person');
74             $Person->add_column( Fey::Column->new( name => 'first_name', type => 'varchar' ) );
75             $Person->add_column( Fey::Column->new( name => 'last_name', type => 'varchar' ) );
76              
77             $schema->add_table( $Person );
78              
79             my @people = (
80             { first_name => 'Homer', last_name => 'Simpson' },
81             { first_name => 'Marge', last_name => 'Simpson' },
82             { first_name => 'Bart', last_name => 'Simpson' },
83             );
84              
85             foreach my $person (@people) {
86             $Person->insert( %$person )->execute;
87             }
88              
89             my ($first_name, $last_name) = $Person->select
90             ->where( $Person->column('first_name'), '==', 'Homer' )
91             ->execute
92             ->fetchrow;
93              
94             =head1 DESCRIPTION
95              
96             This is a subclass of L<Fey::Table> that adds a couple methods for creating
97             L<FeyX::Active::SQL> objects.
98              
99             =head1 METHODS
100              
101             All these methods will pass the C<default_source> database handle from the
102             associated L<FeyX::Active::Schema> to the L<FeyX::Active::SQL> object it
103             creates.
104              
105             =over 4
106              
107             =item B<select ( ?@columns )>
108              
109             This will create a L<FeyX::Active::SQL::Select> object which that will
110             execute against the table associated. You can either pass in a list of
111             L<Fey::Column> objects to be passed to the L<select> method, or pass in
112             nothing which will be interpreted as selecting all the columns.
113              
114             =item B<delete>
115              
116             This will create a L<FeyX::Active::SQL::Delete> object which that will
117             execute against the table associated.
118              
119             =item B<insert ( ?@values )>
120              
121             This will create a L<FeyX::Active::SQL::Insert> object which that will
122             execute against the table associated. You can optionally pass in the
123             set of values you wish to insert and they will be passed to the C<values>
124             method.
125              
126             =item B<update ( ?@values )>
127              
128             This will create a L<FeyX::Active::SQL::Update> object which that will
129             execute against the table associated. You can optionally pass in the
130             set of values you wish to update and they will be passed to the C<set>
131             method.
132              
133             =back
134              
135             =head1 BUGS
136              
137             All complex software has bugs lurking in it, and this module is no
138             exception. If you find a bug please either email me, or add the bug
139             to cpan-RT.
140              
141             =head1 AUTHOR
142              
143             Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
144              
145             =head1 COPYRIGHT AND LICENSE
146              
147             Copyright 2009-2010 Infinity Interactive, Inc.
148              
149             L<http://www.iinteractive.com>
150              
151             This library is free software; you can redistribute it and/or modify
152             it under the same terms as Perl itself.
153              
154             =cut