ARS-Simple

 view release on metacpan or  search on metacpan

lib/ARS/Simple.pm  view on Meta::CPAN


 use ARS::Simple;
 use File::Log;
 my $log = File::Log->new();
 my $ars = ARS::Simple->new({
     server      => 'my_server',
     user        => 'some_admin',
     password    => 'password_for_some_admin',
     log         => $log,
     max_returns => 0,    # allow unlimited returns
     reset_limit => 3000, # reset to a suitable limit after each call using max_returns
     ars_debug   => 1,    # get a whole lot of debugging information (you real should not need)
     });

=head2 get_list

Method to return an array reference of Entry-Id values for a form.
Arguments are passed as an hash reference, with two required parameters, eg:

 # Get theEntry-Id's for all records in the 'User' form.
 my $eids = $ars->get_list({ form => 'User', query => '1 = 1' });

The query parameter can be the same format as you would use in the 'User Tool'
to query a form, however we recommend the use of field ID's (FID) rather than the
default field name as they may change.  I prefer to define a hash of the
forms lables and FID's so that can be used to better document your code, eg

 my %user = ( UserID => 101, UserName => 102 );

the a query could be something like

 my $query = qq{ '$user{UserID}' LIKE "g%" };
 my $eids = $ars->get_list({ form => 'User', query => $query });

=head2 get_data_by_label

Query a form and get the data back as a hash reference where the
keys are the Entry-Id's for the records matched by the query and
the value is a hash reference to the fields you requested where
the keys are the field names you used and the value are the values.

 my $form  = 'form';
 my $query = qq('FID' = "value");
 my $data = $ar->get_data_by_label({
     form  => $form,
     query => $query,
     lfid  => { label1, fid1, label2, fid2, ...},
     });

 $data = {
     eID1, {Label1 => value1, Label2 => value2, ...},
     eID2, {Label1 => value1, Label2 => value2, ...},
     ...
     };

=head2 update_record

Update a record on a form based on the Entry-Id (eid).  The
data to update is defined in the lvp (label value pair) hash reference.
The other required argument is the lfid (label FID) hash reference which
is used to map the labels to field Ids (FID).

The method returns true on success and carps on error.

update_record({
    eid  => $eID,           # The Entry-Id/Request-Id to update
    form => $form,          # The form to update
    lvp  => \%lvp,          # The data to be updated as a label => value hash ref
    lfid => \%labelFIDhash  # The label FID hash reference
    });

=head2 get_SQL

Run direct SQL on your server, there is only one required argument,
the sql, you may optionally set the max_returns value.

The names of the fields can be found from the Admin Tool, under
the database tab for a form.  This will be the name of the field
used in the database view of the Remedy form. B<Note> you do need
to replace spaces with and underscore '_' character.

Example method call:

 my $data = $ars->get_SQL({
     sql => q{select Login_name, Full_Name from User_X where Login_name like 'g%' order by Login_name},
     max_returns => 0,
     });

The return is a hash reference with two keys, numMatches and rows, example:

 $data = {
     numMatches = > 2,
     rows => [
        'greg', 'Greg George',
        'geoff', 'Geoffery Wallace',
     ]
 };

=head2 get_ctl

Returns the ARSystem control structure, so you can use it in other
ARSperl calls.

=head2 get_fields

get_fields has a required argument, the form you require the
field details for.  The returned hash reference is the result
of a call to ars_GetFieldTable, the keys are the field names
and the values are the field ids (fid).

=head2 set_max_entries

This requires that the 'user' has administrator access.  This
allows the overriding of the B<system wide> maximum rows returned
setting AR_SERVER_INFO_MAX_ENTRIES, setting this to zero (0) will
allow unlimited returns.

B<Beware of setting this to a small value, it is system wide and
could have a major impact on your system>

=head1 PRIVATE METHODS

=head2 _init

Initialisation for new and handling of cache

=head2 _load_qualifier

Convert a query to a qualifier structure

=head2 _check_initialised

Check to insure that there is a connection to Remedy ARSystem.
Returns true if connected.

=head2 _reset_max_entries

If set, returns the the system wide AR_SERVER_INFO_MAX_ENTRIES back
to a suitable value (eg 3000).  This required the 'user' has administrator
access

=head2 _carp

Complain if something went wrong & possible add to the log file

=head2 DESTROY

Log out from ARSystem

=head1 ARSperl Programer's Manual

see http://arsperl.sourceforge.net/manual/toc.html

=head1 Default User/Password

The default user and password to use can be configured during install
by the Config.PL script.  This creates a configuration file Simple.cfg
which is stored with Simple.pm.  Unless specified in the call to the
new method, the use and password from Simple.cfg will be used.  This
has the advantage of a single place of change and removes the user and
password from scripts.

Note that the use and password are obfuscated and B<not> encrypted in
the Simple.cfg file.

=head1 TODO

Add in the tools below.

Add in further methods to make life easier and your code more readable

=head1 TOOLS

B<NOT DONE YET>

The lfid array used by the get_data_by_label() method
required that a hash is defined which describes the
field lables (names) you want to use mapped to the
field ID (FID).  The encluded script will construct
such a hash for all relavent fields.  You might like
to edit this down to only those fields you really need
thereby reducing the amount of data returned.

There is a win32 version of this which copies the data
to your clipboard, to make your life easier.

=head1 AUTHOR

Greg George, C<< <gng at cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-ars-simple at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ARS-Simple>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc ARS::Simple

You can also look for information at:

=over 4

=item * RT: CPAN's request tracker (report bugs here)

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ARS-Simple>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/ARS-Simple>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/ARS-Simple>

=item * Search CPAN

L<http://search.cpan.org/dist/ARS-Simple/>

=back

=head1 ACKNOWLEDGEMENTS

This module relies on the ARSperl module and the fantastic effort
by Jeff.C.Murphy and Joel.W.Murphy to write keep ARSperl current over
so many years (along with Bill Middleton & G. David Frye).

 See http://arsperl.sourceforge.net/ for more details.
 and https://metacpan.org/release/ARSperl

Remedy Corporation (long since gone) for making the ARSystem
C API available thereby allowing ARSperl and this module possible

=head1 LICENSE AND COPYRIGHT



( run in 1.267 second using v1.01-cache-2.11-cpan-140bd7fdf52 )