annotate lib/IMPL/ORM.pm @ 417:3ed0c58e9da3 ref20150831

working on di container, tests
author cin
date Mon, 02 Nov 2015 01:56:53 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::ORM;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 use warnings;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use parent qw(IMPL::Object);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::Class::Property;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 use Scalar::Util qw(weaken refaddr);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 use IMPL::Exception;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 our $Depth = 1; # загружать объект + 1 уровень детей
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 our $UseProxy = 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 BEGIN {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 private property _ObjectCache => prop_all;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 private property _MapInstances => prop_all;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 private property _WorkUnit => prop_all;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 public property Schema => prop_all;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 sub ObjectInfoById {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 my ($this,$oid) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 return $this->_ObjectCache->{$oid};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 sub ObjectInfo {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 my ($this,$inst) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 die new IMPL::InvalidOperationException("This method can be used only for a reference") unless ref $inst;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 return $this->_MapInstances->{refaddr $inst};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 =head1 NAME
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43 C<IMPL::ORM> - Object Relational Mapping
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 =head1 SYNOPSIS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 =begin code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 my $ds = IMPL::ORM::Storage::DBIC->new('My::Data',$dsn,$user,$pass,{Autocommit => 1});
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 my $foo = $ds->Insert(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 My::Data::Foo->new(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 'foo class'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 my $bar = $ds->Insert(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59 My::Data::Bar->new(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 'bar class'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 $bar->fooObject($foo);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 $ds->Save($bar);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68 my $fooOther = $ds->Retrieve(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 'My::Data::Bar',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71 name => 'bar class',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 fooObject => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 name => 'some foo'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78 =end code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82 =cut