| 1 | # | ||
| 2 | # DESCRIPTION | ||
| 3 | # PerlORM - Object relational mapper (ORM) for Perl. PerlORM is Perl | ||
| 4 | # library that implements object-relational mapping. Its features are | ||
| 5 | # much similar to those of Java's Hibernate library, but interface is | ||
| 6 | # much different and easier to use. | ||
| 7 | # | ||
| 8 | # AUTHOR | ||
| 9 | # Alexey V. Akimov <akimov_alexey@sourceforge.net> | ||
| 10 | # | ||
| 11 | # COPYRIGHT | ||
| 12 | # Copyright (C) 2005-2006 Alexey V. Akimov | ||
| 13 | # | ||
| 14 | # This library is free software; you can redistribute it and/or | ||
| 15 | # modify it under the terms of the GNU Lesser General Public | ||
| 16 | # License as published by the Free Software Foundation; either | ||
| 17 | # version 2.1 of the License, or (at your option) any later version. | ||
| 18 | # | ||
| 19 | # This library is distributed in the hope that it will be useful, | ||
| 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 22 | # Lesser General Public License for more details. | ||
| 23 | # | ||
| 24 | # You should have received a copy of the GNU Lesser General Public | ||
| 25 | # License along with this library; if not, write to the Free Software | ||
| 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 27 | # | ||
| 28 | |||
| 29 | package ORM::StatMetaprop; | ||
| 30 | |||
| 31 | $VERSION = 0.81; | ||
| 32 | |||
| 33 | use Carp; | ||
| 34 | use ORM::Ident; | ||
| 35 | |||
| 36 | sub new | ||
| 37 | { | ||
| 38 | my $class = shift; | ||
| 39 | my %arg = @_; | ||
| 40 | my $self = { stat_class => $arg{stat_class} }; | ||
| 41 | |||
| 42 | return bless $self, $class; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub AUTOLOAD | ||
| 46 | { | ||
| 47 | my $self = shift; | ||
| 48 | my $meta; | ||
| 49 | |||
| 50 | if( ref $self ) | ||
| 51 | { | ||
| 52 | my $prop = substr( $AUTOLOAD, rindex( $AUTOLOAD, '::' )+2 ); | ||
| 53 | my $prop_meta_expr = $self->{stat_class}->data->{$prop}; | ||
| 54 | |||
| 55 | if( $prop_meta_expr ) | ||
| 56 | { | ||
| 57 | my $prop_meta_class = ref $prop_meta_expr; | ||
| 58 | |||
| 59 | if( $prop_meta_class ) | ||
| 60 | { | ||
| 61 | $meta = $prop_meta_class->new( expr=>ORM::Ident->new( $prop, $self->{stat_class}->stat_class ) ); | ||
| 62 | } | ||
| 63 | else | ||
| 64 | { | ||
| 65 | croak "Can't detect meta-class for property '$prop' of class '$self->{stat_class}'"; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | else | ||
| 69 | { | ||
| 70 | croak "Class '$self->{stat_class}' has no property '$prop'"; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | else | ||
| 74 | { | ||
| 75 | croak "Undefined static method called: $AUTOLOAD"; | ||
| 76 | } | ||
| 77 | |||
| 78 | return $meta; | ||
| 79 | } |