# Global.pm: Class Used for Managing Global Variables package RDA::Value::Global; # $Id: Global.pm,v 1.9 2015/02/12 13:15:15 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/RDA/Value/Global.pm,v 1.9 2015/02/12 13:15:15 RDA Exp $ # # Change History # 20150212 MSC Add the is_editable method. =head1 NAME RDA::Value::Global - Class Used for Managing Global Variables =head1 SYNOPSIS require RDA::Value::Global; =head1 DESCRIPTION The objects of the C class are used to manage global variables. The following methods are available: =cut use strict; BEGIN { use Exporter; use RDA::Text qw(get_string); use RDA::SDCL::Value; use RDA::Value::Scalar; } # Define the global public variables use vars qw($STRINGS $VERSION @ISA); $VERSION = sprintf('%d.%02d', q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/); @ISA = qw(RDA::SDCL::Value Exporter); # Define the global private constants # Define the global private variables # Report the package version sub Version { return $VERSION; } =head2 S<$h = RDA::Value::Global-Enew($ctx,$nam)> The object constructor. It takes the execution context reference and the variable name as extra arguments. A C is represented by a blessed hash reference. The following special keys are used: =over 12 =item S< B<'ctx' > > Reference to the execution context =item S< B<'edt' > > Editable indicator =item S< B<'nam' > > Variable name =item S< B<'var' > > Variable type =back =cut sub new { my ($cls, $ctx, $nam) = @_; # Create the variable value object and return its reference return bless { ctx => $ctx, edt => $nam ne uc($nam), nam => $nam, var => substr($nam, 0, 1), }, ref($cls) || $cls; } =head2 S<$h-Edump([$level[,$text[,$trace]]])> This method returns a string containing the value dump. You can provide an indentation level, a prefix text, and a trace indicator as extra parameters. =cut sub dump ## no critic (Builtin) { my ($slf, $lvl, $txt) = @_; $lvl = 0 unless defined($lvl); $txt = q{} unless defined($txt); return dump_object($slf, {}, $lvl, $txt); } sub dump_object { my ($slf, $tbl, $lvl, $txt) = @_; return q{ } x $lvl.$txt.q{Global=}.$slf->{'nam'}; } =head2 S<$h-Eis_editable> This method indicates whether the value can be modified. =cut sub is_editable { return shift->{'edt'}; } =head1 ASSIGN AND EVAL METHODS =head2 S<$h-Eeval_value([$flg])> This method resolves a variable. When the flag is set, it executes code values. =cut sub eval_value { my ($slf, $flg) = @_; return $slf->{'ctx'}->get_object($slf->{'nam'})->eval_value($flg); } # --- Find object mechanim ---------------------------------------------------- sub find_object { my ($slf, $typ) = @_; my $val; # Treat a request without creating the variable return ($slf->{'ctx'}->get_object($slf->{'nam'})) unless $typ; # Get the variable value, creating the variable when needed die get_string('INCOMPATIBLE') unless $slf->{'var'} eq $typ || $slf->{'var'} eq q{$}; $val = $slf->{'ctx'}->get_object($slf->{'nam'}); return ($val, [$slf->{'ctx'}, $slf->{'nam'}, $val]); } 1; __END__ =head1 SEE ALSO L, L, L, L, L, L =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut