package RDA::Macro::Invent; # $Id: Invent.pm,v 1.5 2008/02/25 14:55:26 mschenke Exp $ # ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/RDA/Macro/Invent.pm,v 1.5 2008/02/25 14:55:26 mschenke Exp $ # # Change History # 20080225 MSC Change the copyright notice. =head1 NAME RDA::Macro::Invent - Class Used for Inventory Macros =head1 SYNOPSIS require RDA::Macro::Invent; =head1 DESCRIPTION The objects of the C class are used to interface with inventory-related macros. The following methods are available: =cut use strict; BEGIN { use Exporter; } # Define the global public variables use vars qw($VERSION); $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/); # Define the global private variables my %tb_fct = ( 'getLocation' => [\&_m_get_location, 'T'], 'getVersion' => [\&_m_get_version, 'T'], 'hasInventory' => [\&_m_has_inventory, 'N'], ); # Report the module version number sub Version { $VERSION; } =head2 S<$h = RDA::Macro::Invent-Enew($agt)> The object constructor. It takes the agent object reference as an argument. C is represented by a blessed hash reference. The following special keys are used: =over 16 =item B< '_agt' > Reference to the agent object =item B< '_dis' > Auto discovery object reference =back Internal keys are prefixed by an underscore. =cut sub new { my $slf = shift; my $class = ref($slf) || $slf; my $agt = shift; # Create the macro object $slf = bless {_agt => $agt}, $class; # Register the macros $agt->register($slf, [keys(%tb_fct)]); # Return the object reference $slf; } =head2 S<$h-Erun($name,$arg,$ctx)> This method executes the macro with the specified argument list in a given context. =cut sub run { my ($slf, $nam, $arg, $ctx) = @_; my ($fct, $ret, $typ); $fct = $tb_fct{$nam}; $typ = $fct->[1]; # Treat an array context return RDA::Value::new_list(&{$fct->[0]}($slf, $ctx, $arg->eval_as_array)) if $typ eq 'L'; # Treat a scalar context $ret = &{$fct->[0]}($slf, $ctx, $arg->eval_as_array); $typ = 'U' unless defined($ret); return RDA::Value->new($typ, $ret); } =head1 INVENTORY MACROS =head2 S This macro returns the location of the specified component. It returns an undefined value when there is no inventory information. =cut sub _m_get_location { my ($slf, $ctx, $nam, $dft) = @_; $dft = $slf->find('LOCATION',$nam,$dft) if ($slf = $slf->_discover); $dft; } =head2 S This macro returns the version of the specified component. It returns an undefined value when there is no inventory information. =cut sub _m_get_version { my ($slf, $ctx, $nam, $dft) = @_; $dft = $slf->find('VERSION',$nam,$dft) if ($slf = $slf->_discover); $dft; } =head2 S This macro indicates whether inventory information is available. =cut sub _m_has_inventory { defined(shift->_discover); } # --- Internal functions ------------------------------------------------------ # Get the auto discovery object sub _discover { my ($slf) = @_; return $slf->{'_dis'} if exists($slf->{'_dis'}); $slf->{'_dis'} = $slf->{'_agt'}->discover; $slf->{'_dis'}; } 1; __END__ =head1 SEE ALSO See also L, L, L, L. =head1 COPYRIGHT NOTICE Copyright (c) 2002-2008, Oracle. All rights reserved. =head1 TRADEMARK NOTICE Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. =cut