]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application.pm
cd4dbbf9c09bb6a75ddfe2b922fc6ef1823202e5
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application.pm
1 package OpenILS::Application;
2 use OpenSRF::Application;
3 use UNIVERSAL::require;
4 use base qw/OpenSRF::Application/;
5
6 sub ils_version {
7     # version format is "x-y-z", for example "2-0-0" for Evergreen 2.0.0
8     # For branches, format is "x-y"
9     return "HEAD";
10 }
11
12 __PACKAGE__->register_method(
13     api_name    => 'opensrf.open-ils.system.ils_version',
14     api_level   => 1,
15     method      => 'ils_version',
16 );
17
18 __PACKAGE__->register_method(
19     api_name => 'opensrf.open-ils.fetch_idl.file',
20     api_level => 1,
21     method => 'get_idl_file',
22 );
23 sub get_idl_file {
24     use OpenSRF::Utils::SettingsClient;
25     return OpenSRF::Utils::SettingsClient->new->config_value('IDL');
26 }
27
28 sub register_method {
29     my $class = shift;
30     my %args = @_;
31     my %dup_args = %args;
32
33     $class = ref($class) || $class;
34
35     $args{package} ||= $class;
36     __PACKAGE__->SUPER::register_method( %args );
37
38     if (exists($dup_args{authoritative}) and $dup_args{authoritative}) {
39         (my $name = $dup_args{api_name}) =~ s/$/.authoritative/o;
40         if ($name ne $dup_args{api_name}) {
41             $dup_args{real_api_name} = $dup_args{api_name};
42             $dup_args{method} = 'authoritative_wrapper';
43             $dup_args{api_name} = $name;
44             $dup_args{package} = __PACKAGE__;
45             __PACKAGE__->SUPER::register_method( %dup_args );
46         }
47     }
48 }
49
50 sub authoritative_wrapper {
51
52     if (!$OpenILS::Utils::CStoreEditor::_loaded) {
53         die "Couldn't load OpenILS::Utils::CStoreEditor!" unless 'OpenILS::Utils::CStoreEditor'->use;
54     }
55
56     my $self = shift;
57     my $client = shift;
58     my @args = @_;
59
60     my $method = $self->method_lookup($self->{real_api_name});
61     die unless $method;
62
63     local $OpenILS::Utils::CStoreEditor::always_xact = 1;
64
65     $client->respond( $_ ) for ( $method->run(@args) );
66
67     OpenILS::Utils::CStoreEditor->flush_forced_xacts();
68
69     return undef;
70 }
71
72 1;
73