/usr/share/perl5/CipUX/Object/Client.pm is in libcipux-object-perl 3.4.0.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | # +==========================================================================+
# || CipUX::Object::Client ||
# || ||
# || CipUX Object Client ||
# || ||
# || Copyright (C) 2008 - 2009 by Christian Kuelker. All rights reserved! ||
# || ||
# || License: GNU General Public License - GNU GPL version 2 ||
# || or (at your opinion) any later version. ||
# || ||
# +==========================================================================+
# ID: $Id: Client.pm 5011 2010-07-30 23:31:16Z christian-guest $
# Revision: $Revision: 5011 $
# Head URL: $HeadURL$
# Date: $Date: 2010-07-31 01:31:16 +0200 (Sat, 31 Jul 2010) $
# Source: $Source$
package CipUX::Object::Client;
use 5.008001;
use strict;
use warnings;
use Carp;
use Class::Std;
use CipUX::Object::Action::Create;
use CipUX::Object::Action::Destroy;
use CipUX::Object::Action::List;
use Data::Dumper;
use English qw( -no_match_vars);
use Getopt::Long; # command line options
use Log::Log4perl qw(:easy);
use Pod::Usage;
use Readonly;
use base qw(CipUX::Object::Action);
{ # BEGIN INSIDE-OUT CLASS
use version; our $VERSION = qv('3.4.0.5');
use re 'taint'; # Keep data captured by parens tainted
delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)}; # Make %ENV safe
# +======================================================================+
# || CONSTANTS ||
# +======================================================================+
Readonly::Scalar my $EMPTY_STRING => q{};
Readonly::Scalar my $LINEWIDTH => 78;
Readonly::Scalar my $L4PCONF => '/etc/cipux/log4perl.conf';
Readonly::Array my @ACTION => qw( list create destroy);
# +======================================================================+
# || INIT ARGS ||
# +======================================================================+
# register client with name:
# name : cipux_object_client
my %name_of : ATTR( init_arg => 'name');
# +======================================================================+
# || GLOBALS ||
# +======================================================================+
my $L = q{=} x $LINEWIDTH;
$L .= "\n";
my $mattrvalue_hr = {};
my %opt = ();
my $script = $EMPTY_STRING;
my %option = (
'cipux_object_client' => {
'must' => [qw(a=action)],
'may' => [
qw(c cfg D debug h ? help p pretty V verbose version x mattrvalue t type o object)
],
'not' => [],
},
'list' => {
'must' => [qw()],
'may' => [qw(c cfg D debug h ? help p pretty V verbose version )],
'not' => [qw(x mattrvalue t type o object)],
},
'create' => {
'must' => [qw(t=type o=object)],
'may' =>
[qw(c cfg D debug h ? help mattrvalue V verbose version x)],
'not' => [qw(p pretty)],
},
'destroy' => {
'must' => [qw(t=type o=object)],
'may' => [qw(c cfg D debug h ? help V verbose version )],
'not' => [qw(p pretty x mattrvalue)],
},
);
sub run {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
# constructor parameter from CipUX::Object::Client
my $script = $name_of{ ident $self};
# test right away if we have a valid name
if ( $script ne 'cipux_object_client' ) {
$self->exc( { msg => 'unknown script name', value => $script } );
}
# +------------------------------------------------------------------+
# | Environment
Getopt::Long::Configure('bundling');
GetOptions(
\%opt,
'action|a=s',
'cfg|c=s',
'debug|D',
'help|h',
'object|o=s',
'pretty|p',
'type|t=s',
'version|V',
'verbose',
'mattrvalue|x=s%' =>
sub { $self->store_mattrvalue( $mattrvalue_hr, \%opt, @_ ); },
)
or pod2usage(
-exitstatus => 2,
-msg => "$L problems parsing command line!\n$L"
);
if ( exists $opt{debug} ) {
Log::Log4perl->init_once($L4PCONF);
}
my $logger = get_logger(__PACKAGE__);
$logger->debug('SUB');
# display help page
if ( exists $opt{help} ) {
pod2usage( -exitstatus => 0, -verbose => 1 );
}
if ( exists $opt{version} ) {
$self->out("$script $VERSION\n");
exit 0;
}
my $run_action = exists $opt{action} ? $opt{action} : undef;
if ( not defined $run_action ) {
my $msg = "$L Please give parameter --action or -a! \n";
$msg .= "valid object actions are: \n";
foreach my $a (@ACTION) {
$msg .= "$a\n";
}
$msg .= $L;
pod2usage( -exitstatus => 1, -verbose => 0, -msg => $msg );
}
$logger->debug( 'run_action: ', $run_action );
my $ret = $self->test_cli_option(
{
script => $run_action,
logic_hr => \%option,
opt_hr => \%opt,
debug => 0,
}
);
# +------------------------------------------------------------------+
# | main
my $action
= exists $opt{action}
? $opt{action}
: undef;
my $pretty
= exists $opt{pretty}
? 1
: 0;
my $object
= exists $opt{object}
? $opt{object}
: undef;
my $type
= exists $opt{type}
? $opt{type}
: undef;
my $cfg
= exists $opt{cfg}
? $opt{cfg}
: undef;
$logger->debug( 'pretty: ', $pretty );
if ( defined $object ) {
$logger->debug( 'object: ', $object );
}
if ( defined $type ) {
$logger->debug( 'type: ', $type );
}
if ( defined $cfg ) {
$logger->debug( 'cfg: ', $cfg );
}
if ( scalar( grep { $_ eq $action } @ACTION ) < 1 ) {
my $msg = "unknown object action [$action]\n";
$msg .= "valid object actions are: \n";
foreach my $a (@ACTION) {
$msg .= "$a\n";
}
$msg .= $L;
$self->exc( { msg => $msg } );
}
my $sub = 'cipux_object_' . $run_action;
$self->$sub(
{
action => $action,
pretty => $pretty,
type => $type,
object => $object,
cfg => $cfg,
mattrvalue_hr => $mattrvalue_hr,
}
);
return;
}
# +----------------------------------------------------------------------+
# | cipux_object_list |
# +----------------------------------------------------------------------+
sub cipux_object_list {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
my $cfg
= exists $arg_r->{cfg}
? $self->l( $arg_r->{cfg} )
: $self->perr('cfg');
my $pretty
= exists $arg_r->{pretty}
? $self->l( $arg_r->{pretty} )
: $self->perr('pretty');
#foreach my $p (qw(cfg)) {
# if ( not defined $arg_r->{$p} ) {
# my $msg = 'parameter not defined in sub cipux_object_list';
# $self->exc( { msg => $msg, value => $p } );
# }
#}
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug('SUB cipux_object_list');
$logger->debug( 'pretty: ', $pretty );
$logger->debug( 'cfg: ', { filter => \&Dumper, value => $cfg } );
$self->_print_list_type( { pretty => $pretty, cfg => $cfg } );
# +------------------------------------------------------------------+
# | API
return;
}
# +----------------------------------------------------------------------+
# | cipux_object_create |
# +----------------------------------------------------------------------+
sub cipux_object_create {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
my $type
= exists $arg_r->{type}
? $self->l( $arg_r->{type} )
: $self->perr('type');
my $object
= exists $arg_r->{object}
? $self->l( $arg_r->{object} )
: $self->perr('object');
my $cfg
= exists $arg_r->{cfg}
? $self->l( $arg_r->{cfg} )
: $self->perr('cfg');
my $mattrvalue_hr
= exists $arg_r->{mattrvalue_hr}
? $self->h( $arg_r->{mattrvalue_hr} )
: $self->perr('mattrvalue_hr');
foreach my $p (qw(type object)) {
if ( not defined $arg_r->{$p} ) {
my $msg = 'parameter not defined in sub cipux_object_create';
$self->exc( { msg => $msg, value => $p } );
}
}
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
my $cfg_coupling_hr = $self->get_coupling_cfg();
my $cfg_object_hr = $self->get_object_cfg();
my $cfg_basis_hr = $self->get_basis_cfg();
my $create = CipUX::Object::Action::Create->new( { cfg => $cfg } );
my $return = $create->create_object_action(
{
action => 'create_object_action',
type => $type,
object => $object,
attr_hr => $mattrvalue_hr,
#overwrite_hr => $overwrite_hr, # TODO define that in CipUX::Object
}
);
# +------------------------------------------------------------------+
# | API
return $return;
}
sub cipux_object_destroy {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
my $type
= exists $arg_r->{type}
? $self->l( $arg_r->{type} )
: $self->perr('type');
my $object
= exists $arg_r->{object}
? $self->l( $arg_r->{object} )
: $self->perr('object');
my $cfg
= exists $arg_r->{cfg}
? $self->l( $arg_r->{cfg} )
: $self->perr('cfg');
foreach my $p (qw(type object )) {
if ( not defined $arg_r->{$p} ) {
my $msg = 'parameter not defined in sub cipux_object_destroy';
$self->exc( { msg => $msg, value => $p } );
}
}
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug( 'object: ', $object );
$logger->debug( 'type: ', $type );
my $cfg_coupling_hr = $self->get_coupling_cfg();
my $cfg_object_hr = $self->get_object_cfg();
my $cfg_basis_hr = $self->get_basis_cfg();
$logger->debug(
'cfg_coupling_hr',
{
filter => \&Dumper,
value => $cfg_coupling_hr
}
);
my $destroy = CipUX::Object::Action::Destroy->new(
{
cfg_coupling_hr => $cfg_coupling_hr,
cfg_object_hr => $cfg_object_hr,
cfg_basis_hr => $cfg_basis_hr
}
);
my $return = $destroy->destroy_object_action(
{
action => 'destroy_object_action',
type => $type,
object => $object,
}
);
# +------------------------------------------------------------------+
# | API
return 1;
}
# +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
# | PRIVATE INTERFACE |
# +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
sub _print_list_type {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
my $pretty
= exists $arg_r->{pretty} ? $self->l( $arg_r->{pretty} ) : 0;
my $cfg = exists $arg_r->{cfg} ? $self->l( $arg_r->{cfg} ) : 0;
my $logger = get_logger(__PACKAGE__);
$logger->debug( 'pretty: ', $pretty );
$logger->debug( 'cfg: ', $cfg );
my $cfg_coupling_hr = $self->get_coupling_cfg();
my $cfg_object_hr = $self->get_object_cfg();
my $cfg_basis_hr = $self->get_basis_cfg();
$logger->debug(
'cfg_coupling_hr: ',
{
filter => \&Dumper,
value => $cfg_coupling_hr
}
);
my $list_ar
= $self->list_type( { cfg_coupling_hr => $cfg_coupling_hr } );
$logger->debug(
'list_ar',
{
filter => \&Dumper,
value => $list_ar
}
);
# this is without pretty print!
#
# foreach my $line (@$list_ar){
# chomp($line);
# $self->out( "$line\n");
# }
# mostly this stuff is for pretty print
my $max_col = 0;
my $width = 0;
if ($pretty) {
foreach my $line ( @{$list_ar} ) {
if ( $max_col < length $line ) { $max_col = length $line; }
}
$width = 2 + $max_col;
$self->out( q{+} . q{-} x $width . "+\n" );
$self->out( sprintf '| %-' . $max_col . "s |\n", 'type' );
$self->out( q{+} . q{=} x $width . "+\n" );
}
foreach my $line ( @{$list_ar} ) {
chomp $line;
if ($pretty) {
$self->out( sprintf '| %-' . $max_col . "s |\n", $line );
}
else {
$self->out("$line\n");
}
}
if ($pretty) { $self->out( q{+} . q{-} x $width . "+\n" ); }
# +------------------------------------------------------------------+
# | API
return;
}
# +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
# | PUBLIC INTERFACE |
# +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
sub DEMOLISH {
# +------------------------------------------------------------------+
# | API
my ($self) = @_;
# actualize library information
#Library->remove($self);
# +------------------------------------------------------------------+
# | API
return;
}
# +======================================================================+
# || METHODS ||
# +======================================================================+
} # END INSIDE-OUT CLASS
1; # Magic true value required at end of module
__END__
=head1 NAME
CipUX::Object::Client - Command line client for CipUX objects
=head1 VERSION
This document describes CipUX::Object::Client version 3.4.0.5
=head1 SYNOPSIS
use CipUX::Object::Client;
my $c = CipUX::Object::Client->new({name=>'cipux_object_client'});
$c->run();
=head1 DESCRIPTION
Command line client library for CipUX Object.
=head1 SUBROUTINES/METHODS
=head2 DEMOLISH
TODO
=head2 run
TODO
=head2 cipux_object_create
TODO
=head2 cipux_object_destroy
TODO
=head2 cipux_object_list
TODO
=head1 DIAGNOSTICS
=for author to fill in:
List every single error and warning message that the module can
generate (even the ones that will "never happen"), with a full
explanation of each problem, one or more likely causes, and any
suggested remedies.
=over
=item C<< Error message here, perhaps with %s placeholders >>
[Description of error here]
=item C<< Another error message here >>
[Description of error here]
[Et cetera, et cetera]
=back
=head1 CONFIGURATION AND ENVIRONMENT
CipUX::Object::Client requires no configuration files or environment variables.
=head1 DEPENDENCIES
TODO
=head1 INCOMPATIBILITIES
None reported.
=head1 BUGS AND LIMITATIONS
No bugs have been reported.
=head1 SEE ALSO
See the CipUX webpage and the manual at L<http://www.cipux.org>
=head1 AUTHOR
Christian Kuelker C<< <christian.kuelker@cipworx.org> >>
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2008 - 2009 , Christian Kuelker. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
=head1 DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
=cut
|