lib/Oryx.pm

filter: Statementstmt 100% 6 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 8 / 8 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Oryx/Schema/Stub.pm ↑ Summary
1 package Oryx;
2  
3 18 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use UNIVERSAL qw(isa can);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use Oryx::Class;
6  
7 our $VERSION = '0.24';
8 our $DEBUG = 0;
9  
10 sub new { croak("abstract") }
11  
12 sub import {
13 my $class = shift;
14 my %param = @_;
15 if (defined $param{auto_deploy}) {
16 Oryx::Class->auto_deploy($param{auto_deploy});
17 }
18 if (defined $param{dont_cache}) {
19 Oryx::Class->dont_cache($param{dont_cache});
20 }
21 }
22  
23 sub init {
24 my ($self, $Class, $conn, $schema) = @_;
25  
26 $DEBUG && $self->_carp("SCHEMA => $schema, Class => $Class");
27 unless (ref($schema) and isa($schema, 'Oryx::Schema')) {
28 $schema = 'Oryx::Schema' unless $schema;
29 eval "use $schema"; croak($@) if $@;
30 $schema = $schema->new;
31 $DEBUG && $self->_carp("new schema instance => $schema");
32 }
33  
34 $self->schema($schema);
35 $self->set_util($conn->[0]); # $dsname
36  
37 push @Oryx::Class::ISA, $Class;
38 $self->Class($Class);
39 $self->Class->storage($self);
40  
41 if (%Oryx::Class::Orphans) {
42 foreach (keys %Oryx::Class::Orphans) {
43 eval { Oryx::Class::import($_) };
44 $DEBUG && $_->_carp($@) if $@;
45 $schema->addClass($_);
46 }
47 %Oryx::Class::Orphans = ();
48 }
49 }
50  
51 sub connect {
52 my ($class, $conn, $schema) = @_;
53 $schema = 'Oryx::Schema' unless $schema;
54  
55 # determine the type of storage we're using from the dsn
56 my $storage;
57 if ($conn->[0] =~ /^dbm:/) {
58 eval 'use Oryx::DBM'; $class->_croak($@) if $@;
59 $storage = Oryx::DBM->new;
60 } else {
61 eval 'use Oryx::DBI'; $class->_croak($@) if $@;
62 $storage = Oryx::DBI->new;
63 }
64  
65 $storage->connect($conn, $schema);
66 return $storage;
67 }
68  
69 sub Class { $_[0]->{Class} = $_[1] if $_[1]; $_[0]->{Class} }
70  
71 # delegate to the actual implementing storage class
72 sub deploySchema {
73 my ($self, $schema) = @_;
74 $self->Class->storage->deploySchema($schema);
75 }
76  
77 sub _carp {
78 my $class = ref $_[0] || $_[0];
79 carp("[".$class."] $_[1]");
80 }
81  
82 sub _croak {
83 my $class = ref $_[0] || $_[0];
84 croak("[".$class."] $_[1]");
85 }
86  
87 1;
88  
89 __END__
« blib/lib/Oryx/Schema/Stub.pm ↑ Summary