File Coverage

lib/UR/Context/Root.pm
Criterion Covered Total %
statement 6 35 17.1
branch 0 14 0.0
condition 0 2 0.0
subroutine 2 7 28.5
pod 2 4 50.0
total 10 62 16.1


line stmt bran cond sub pod time code
1             package UR::Context::Root;
2              
3 266     266   2643 use strict;
  266         347  
  266         7854  
4 266     266   1059 use warnings;
  266         340  
  266         112373  
5              
6             require UR;
7             our $VERSION = "0.46"; # UR $VERSION;
8              
9             UR::Object::Type->define(
10             class_name => 'UR::Context::Root',
11             is => ['UR::Singleton', 'UR::Context'],
12             is_abstract => 1,
13             is_transactional => 1,
14             doc => 'A base level context, representing the committed state of datasources external to the application.',
15             );
16              
17             # this is called automatically by UR.pm at the end of the module
18             my $initialized = 0;
19             sub _initialize_for_current_process {
20 0     0     my $class = shift;
21 0 0         if ($initialized) {
22 0           die "Attempt to re-initialize the current process?";
23             }
24 0   0       my $context_singleton_class = $ENV{UR_CONTEXT_ROOT} ||= 'UR::Context::DefaultRoot';
25 0           $class->set_current($context_singleton_class);
26             }
27              
28             sub name {
29 0     0 1   my $class = shift->_singleton_class_name;
30 0           my ($name) = ($class =~ /^\w+?\:\:\w+?\:\:(\w+)$/);
31 0 0         die "failed to parse name from $class!" unless $name;
32 0           return lc($name);
33             }
34              
35             sub get_current {
36             #shift->_initialize_for_current_process() unless $initialized;
37             #eval "sub get_current { \$ENV{UR_CONTEXT_ROOT} }";
38 0     0 1   return $ENV{UR_CONTEXT_ROOT};
39             }
40              
41             sub set_current {
42 0     0 0   my $class = shift;
43 0           my $value = shift;
44            
45 0 0         return $value if $value eq $ENV{UR_CONTEXT_ROOT};
46            
47 0           $ENV{UR_CONTEXT_ROOT} = $value;
48            
49             #print "base context set to $value\n";
50             #print Carp::longmess();
51            
52 0           eval {
53 0           local $SIG{__DIE__};
54 0           local $SIG{__WARN__};
55 0           $ENV{UR_CONTEXT_ROOT}->class;
56             };
57            
58 0 0         if ($@) {
59             die "The context at application initialization is set to "
60 0           . $ENV{UR_CONTEXT_ROOT} . ".\n"
61             . "This failed to compile:\n$@"
62             }
63            
64 0 0         unless ($ENV{UR_CONTEXT_ROOT}->isa("UR::Context")) {
65             die "The context at application initialization is set to "
66 0           . $ENV{UR_CONTEXT_ROOT} . ".\n"
67             . "This does not inherit from UR::Context."
68             }
69            
70 0 0         unless ($ENV{UR_CONTEXT_ROOT}->__meta__) {
71             die "The context at application initialization is set to "
72 0           . $ENV{UR_CONTEXT_ROOT} . ".\n"
73             . "This is not defined with UR::Object::Type metadata!"
74             }
75              
76             # Initialize the bottom of the transaction stack
77 0 0         if (@UR::Context::Transaction::open_transaction_stack > 1) {
78 0           die "Cannot change the base context once transactions are in progress!"
79             }
80              
81 0           return $value;
82             }
83              
84             sub access_level {
85 0     0 0   my $self = shift->_singleton_object;
86 0           return "???";
87             }
88              
89             # sub has_changes { return }
90              
91             1;
92