blib/lib/UR/ObjectV001removed.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 97 SCAR 40.3
CC
7
Cov
0%
load
30.0
matches
12.0
_load
2.0
CRAP 56.0
1 package UR::Object;
2  
3 =pod
4  
5 =head1 NAME
6  
7 UR::ObjectV001removed - restores changes removed in UR version 0.01
8  
9 =head1 SYNOPSIS
10  
11 use UR::ObjectV001removed
12  
13 =head1 DESCRIPTION
14  
15 Extends the UR::Object API have methods removed in the 0.01 release.
16  
17 If you upgrade UR, but depend on old APIs, use this module.
18  
19 For version 0.xx of UR, APIs may change with each release. After 1.0, APIs will
20 only change with major releases number increments.
21  
22 =cut
23  
24 use warnings;
25 use strict;
26 our $VERSION = "0.46"; # UR $VERSION;
27 use Data::Dumper;
28 use Scalar::Util qw(blessed);
29  
30 *get_class_meta = sub { shift->__meta__ };
31 *get_class_object = sub { shift->__meta__ };
32 *get_rule_for_params = \&define_boolexpr;
33 *get_boolexpr_for_params = \&define_boolexpr;
34 *get_object_set = \&define_set;
35  
36 our ($all_objects_loaded, $all_change_subscriptions, $all_objects_are_loaded, $all_params_loaded);
37  
38 *all_objects_loaded = \$UR::Context::all_objects_loaded;
39 *all_change_subscriptions = \$UR::Context::all_change_subscriptions;
40 *all_objects_are_loaded = \$UR::Context::all_objects_are_loaded;
41 *all_params_loaded = \$UR::Context::all_params_loaded;
42  
43 # These live in UR::Context, where they may switch to point to
44 # different data structures depending on sub-context, transaction, etc.
45  
46 # They are aliased here for backward compatability, since many parts
47 # of the system use $UR::Object::whatever to work with them directly.
48  
49 sub load {
50 # this is here for backward external compatability
51 # get() now goes directly to the context
52
53 my $class = shift;
54 if (ref $class) {
55 # Trying to reload a specific object?
56 if (@_) {
57 Carp::confess("load() on an instance with parameters is not supported");
58 return;
59 }
60 @_ = ('id' ,$class->id());
61 $class = ref $class;
62 }
63  
64 my ($rule, @extra) = UR::BoolExpr->resolve_normalized($class,@_);
65
66 if (@extra) {
67 if (scalar @extra == 2 and $extra[0] eq "sql") {
68 return $UR::Context::current->_get_objects_for_class_and_sql($class,$extra[1]);
69 }
70 else {
71 die "Odd parameters passed directly to $class load(): @extra.\n"
72 . "Processable params were: "
73 . Data::Dumper::Dumper({ $rule->params_list });
74 }
75 }
76 return $UR::Context::current->get_objects_for_class_and_rule($class,$rule,1);
77 }
78  
79 sub _load {
80 Carp::cluck();
81 my ($class,$rule) = @_;
82 return $UR::Context::current->get_objects_for_class_and_rule($class,$rule,1);
83 }
84  
85 sub dbh {
86 Carp::confess("Attempt to call dbh() on a UR::Object.\n"
87 . "Objects no longer have DB handles, data_sources do\n"
88 . "use resolve_data_sources_for_class_meta_and_rule() on a UR::Context instead");
89 my $ds = $UR::Context::current->resolve_data_sources_for_class_meta_and_rule(shift->__meta__);
90 return $ds->get_default_handle;
91 }
92  
93  
94 sub matches {
95 no warnings;
96 my $self = shift;
97 my %param = $self->preprocess_params(@_);
98 for my $key (keys %param) {
99 next unless $self->can($key);
100 return 0 unless $self->$key eq $param{$key}
101 }
102 return 1;
103 }
104  
105 sub property_names {
106 my $class = shift;
107 my $meta = $class->__meta__;
108 return $meta->all_property_names;
109 }
110  
111 sub _is_loaded {
112 Carp::cluck();
113 my ($class,$rule) = @_;
114 return $UR::Context::current->get_objects_for_class_and_rule($class,$rule,0);
115 }
116  
117 # as we remove more logic from the default API, add extensions here.
118 use UR::ObjectV04removed;
119