Created
October 21, 2015 21:16
-
-
Save jeffa/660c1c29cbc881f681c7 to your computer and use it in GitHub Desktop.
ORM proof of concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package DBIx::Object; | |
| use base 'DBI'; | |
| package DBIx::Object::st; | |
| use base 'DBI::st'; | |
| package DBIx::Object::db; | |
| use base 'DBI::db'; | |
| use Moose; | |
| around 'selectall_arrayref' => sub { | |
| my $orig = shift; | |
| my $self = shift; | |
| return $self->$orig(@_) unless ref($_[1]) eq 'HASH' and exists $_[1]->{Class}; | |
| my $class = delete $_[1]->{Class}; | |
| $_[1]->{Slice} = {}; | |
| my $arrayref = $self->$orig(@_); | |
| bless $_, $class for @$arrayref; | |
| return $arrayref; | |
| }; | |
| around 'selectall_hashref' => sub { | |
| my $orig = shift; | |
| my $self = shift; | |
| return $self->$orig(@_) unless ref($_[2]) eq 'HASH' and exists $_[2]->{Class}; | |
| my $class = delete $_[2]->{Class}; | |
| my $hashref = $self->$orig(@_); | |
| bless $_, $class for values %$hashref; | |
| return $hashref; | |
| }; | |
| around 'selectrow_hashref' => sub { | |
| my $orig = shift; | |
| my $self = shift; | |
| return $self->$orig(@_) unless ref($_[1]) eq 'HASH' and exists $_[1]->{Class}; | |
| my $class = delete $_[1]->{Class}; | |
| my $hashref = $self->$orig(@_); | |
| return bless $hashref, $class; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment