This file is indexed.

/usr/share/perl5/CipUX/Storage/Client.pm is in libcipux-storage-perl 3.4.0.2-6.1.

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
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
# +==========================================================================+
# || CipUX::Storage::Client                                                 ||
# ||                                                                        ||
# || CipUX storage abstraction layer                                        ||
# ||                                                                        ||
# || Copyright (C) 2008 - 2009 by Christian Kuelker. All rights reserved!   ||
# ||                                                                        ||
# || License: GNU GPL version 2 or any later version.                       ||
# ||                                                                        ||
# +==========================================================================+
# ID:       $Id$
# Revision: $Revision$
# Head URL: $HeadURL$
# Date:     $Date$
# Source:   $Source$

package CipUX::Storage::Client;

use 5.008001;
use strict;
use warnings;
use Carp;
use Class::Std;
use Data::Dumper;
use English qw( -no_match_vars);
use Getopt::Long;
use Log::Log4perl qw(:easy);
use Pod::Usage;
use Readonly;
use base qw(CipUX CipUX::Storage);

{    # BEGIN CLASS

    use version; our $VERSION = qv('3.4.0.2');
    use re 'taint';    # Keep tainted any data captured by parens
    delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)};    # Make %ENV safe

    # +======================================================================+
    # || CONST                                                              ||
    # +======================================================================+
    Readonly::Scalar my $EMPTY_STRING => q{};
    Readonly::Scalar my $LINEWIDTH    => 78;
    Readonly::Scalar my $L4PCONF      => '/etc/cipux/log4perl.conf';
    Readonly::Array my @ACTION        => qw(
        get_all_values
        set_all_values
        add_node
        get_value
        set_value
        list
        delete_node
        rename_node
    );

    # +======================================================================+
    # || INIT ARGS                                                          ||
    # +======================================================================+

    # register client with name:
    #     name : cipux_storage_client
    my %name_of : ATTR( init_arg => 'name');

    # +======================================================================+
    # || GLOBAL                                                             ||
    # +======================================================================+
    my $L = q{=} x $LINEWIDTH;
    $L .= "\n";

    my $maxcol_ar     = [];
    my $value_ar      = [];
    my $attrvalue_hr  = {};
    my $mattrvalue_hr = {};
    my %opt           = ();
    my %option        = (
        'cipux_storage_client' => {
            'must' => [qw(t=storage_task l=list)],
            'may' => [qw(c cfg h ? help D debug p pretty V verbose version )],
            'not' => [qw(a add c d e r t v x y)],
        },
        'add_node' => {
            'must' => [qw(t=storage_task x=mattrvalue s=type o=object)],
            'may'  => [qw(c cfg h ? help D debug V verbose version )],
            'not'  => [
                qw(a add d delete e erase p prettey r replace v value y attrvalue)
            ],
        },
        'delete_node' => {
            'must' => [qw(t=storage_task s=type o=object)],
            'may'  => [qw(c cfg h ? help D debug V verbose version )],
            'not'  => [
                qw(a add d delete e erase p prettey r replace v value x mattrvalue y attrvalue)
            ],
        },
        'rename_node' => {
            'must' => [qw(t=storage_task s=type o=object v=value)],
            'may'  => [qw(c cfg h ? help D debug V verbose version )],
            'not'  => [
                qw(a add d delete e erase p prettey r replace y attrvalue x mattrvalue)
            ],
        },
        'get_value' => {
            'must' => [qw(t=storage_task y=attrvalue s=type o=object)],
            'may'  => [qw(c cfg h ? help D debug pretty V verbose version )],
            'not' =>
                [qw(a add d delete e erase r replace v value x mattrvalue)],
        },
        'get_all_values' => {
            'must' => [qw(t=storage_task y=attrvalue s=type)],
            'may' => [qw(c cfg h ? help D debug p pretty V verbose version )],
            'not' => [
                qw(a add d delete e erase o object r replace v value x mattrvalue)
            ],
        },
        'set_value' => {
            'must' => [qw(t=storage_task y=attrvalue s=type o=object)],
            'may'  => [
                qw(a add d delete c cfg e erase h ? help D debug r replace v value V verbose version )
            ],
            'not' => [qw(p prettey x mattrvalue)],
        },
        'set_all_values' => {
            'must' => [qw(t=storage_task y=attrvalue s=type)],
            'may'  => [
                qw(a add d delete c cfg erase h ? help D debug r replace v value V verbose version )
            ],
            'not' => [qw(o object p prettey x mattrvalue)],
        },
    );

    # +======================================================================+
    # || run                                                                ||
    # +======================================================================+
    sub run {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        # constructor parameter from CipUX::Storage::Client
        my $script = $name_of{ ident $self};

        # test right away if we have a valid name
        if ( $script ne 'cipux_storage_client' ) {
            $self->exc( { msg => 'unknown script name', value => $script } );
        }

        # +------------------------------------------------------------------+
        # | Environment
        Getopt::Long::Configure('bundling');

        my $store_attrvalue
            = sub { $self->store_attrvalue( $attrvalue_hr, @_ ) };
        my $store_mattrvalue
            = sub { $self->store_mattrvalue( $mattrvalue_hr, @_ ) };

        GetOptions(
            \%opt,
            'add|a',
            'cfg|c=s',
            'debug|D',
            'delete|d',
            'erase|e',
            'help|h',
            'list|l',
            'gum|g=i',
            'object|o=s',
            'pretty|p',
            'replace|r',
            'type|s=s',
            'storage_task|t=s',
            'value|v=s',
            'version|V',
            'verbose',
            'mattrvalue|x=s%' =>
                sub { $self->store_mattrvalue( $mattrvalue_hr, \%opt, @_ ); },
            'attrvalue|y:s%' =>
                sub { $self->store_attrvalue( $attrvalue_hr, \%opt, @_ ); },
            )
            or pod2usage(
            -exitstatus => 2,
            -msg        => "$L problems parsing command line!\n$L"
            );

        if ( defined $opt{debug} ) {
            Log::Log4perl->init_once($L4PCONF);
        }

        my $logger = get_logger(__PACKAGE__);
        $logger->debug('BEGIN');

        $logger->debug( 'opt: ', { filter => \&Dumper, value => \%opt } );
        $logger->debug( 'attrvalue_hr: ',
            { filter => \&Dumper, value => $attrvalue_hr } );
        $logger->debug( 'mattrvalue_hr: ',
            { filter => \&Dumper, value => $mattrvalue_hr } );

        # display help page
        if ( exists $opt{help} ) {
            pod2usage( -exitstatus => 0, -verbose => 1 );
        }

        my $storage_task
            = exists $opt{storage_task}
            ? $opt{storage_task}
            : undef;

        if ( not defined $storage_task ) {
            my $msg = "$L Please give parameter --storage_task or -t! \n";
            $msg .= "valid storage tasks are: \n";
            foreach my $a (@ACTION) {
                $msg .= "$a\n";
            }
            $msg .= $L;
            pod2usage( -exitstatus => 1, -verbose => 0, -msg => $msg );
        }
        $logger->debug( 'storage_task: ', $storage_task );

        if ( exists $opt{version} ) {
            $self->out("$script $VERSION\n");
            exit 0;
        }

        my $ret = $self->test_cli_option(
            {
                script   => $storage_task,
                logic_hr => \%option,
                opt_hr   => \%opt,
            }
        );

        # +------------------------------------------------------------------+
        # | main

        my $cfg
            = exists $opt{cfg}
            ? $opt{cfg}
            : undef;

        if ( defined $cfg ) {
            $logger->debug( 'cfg: ', $cfg );
        }

        my $escope
            = exists $opt{erase}
            ? 'all'
            : 'one';

        my $changes
            = exists $opt{erase}   ? 'delete'
            : exists $opt{delete}  ? 'delete'
            : exists $opt{add}     ? 'add'
            : exists $opt{replace} ? 'replace'
            :                        'replace';
        my $scope
            = $storage_task eq 'get_value'      ? 'one'
            : $storage_task eq 'set_value'      ? 'one'
            : $storage_task eq 'get_all_values' ? 'all'
            : $storage_task eq 'set_all_values' ? 'all'
            :                                     'one';

        my $pretty
            = exists $opt{pretty}
            ? 1
            : 0;

        my $object
            = exists $opt{object}
            ? $opt{object}
            : $EMPTY_STRING;

        # s = type
        my $type
            = exists $opt{type}
            ? $opt{type}
            : $EMPTY_STRING;

        my $value
            = exists $opt{value}
            ? $opt{value}
            : $EMPTY_STRING;

        my $configfile
            = exists $opt{cfg}
            ? $opt{cfg}
            : $EMPTY_STRING;

        if ( scalar( grep { $_ eq $storage_task } @ACTION ) < 1 ) {
            my $msg = "unknown storage task [$storage_task]\n";

            $msg .= "valid storage tasks are: \n";
            foreach my $a (@ACTION) {
                $msg .= "$a\n";
            }
            $msg .= $L;
            $self->exc( { msg => $msg } );
        }

        my $sub = 'cipux_storage_' . $storage_task;
        $self->$sub(
            {
                scope  => $scope,
                escope => $escope,
                pretty => $pretty,
                type   => $type,
                object => $object,
                value  => $value,
                cfg    => $cfg,
            }
        );

        return;
    }

    # +----------------------------------------------------------------------+
    # | cipux_storage_list                                                   |
    # +----------------------------------------------------------------------+
    sub cipux_storage_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');

        # +------------------------------------------------------------------+
        # | main
        my $logger = get_logger(__PACKAGE__);
        $logger->debug('BEGIN');
        $logger->debug( 'pretty: ', $pretty );
        $logger->debug( 'cfg: ', { filter => \&Dumper, value => $cfg } );

        $self->_print_list_type( { pretty => $pretty, cfg => $cfg } );

        # +------------------------------------------------------------------+
        # | API
        return;
    }

    # +----------------------------------------------------------------------+
    # | cipux_storage_get_value                                              |
    # +----------------------------------------------------------------------+
    sub cipux_storage_get_value {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $cfg
            = exists $arg_r->{cfg}
            ? $self->l( $arg_r->{cfg} )
            : $self->perr('cfg');

        my $scope
            = exists $arg_r->{scope}
            ? $self->l( $arg_r->{scope} )
            : $self->perr('scope');

        my $pretty
            = exists $arg_r->{pretty}
            ? $self->l( $arg_r->{pretty} )
            : $self->perr('pretty');

        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');

        # +------------------------------------------------------------------+
        # | main
        my $logger = get_logger(__PACKAGE__);
        $logger->debug('BEGIN');

        $logger->debug( 'attrvalue_hr: ',
            { filter => \&Dumper, value => $attrvalue_hr } );

        #$attrvalue_hr->{cipuxAddress} = 'cipuxAddress';

        my $storage = CipUX::Storage->new();

        my $value_hr = $storage->get_value(
            {
                scope   => $scope,
                type    => $type,
                obj     => $object,
                attr_ar => [ %{$attrvalue_hr} ],
            }
        );

        $self->_print_values(
            { scope => $scope, pretty => $pretty, value_hr => $value_hr } );

        # +------------------------------------------------------------------+
        # | API
        return;
    }

    # +----------------------------------------------------------------------+
    # | cipux_storage_get_all_values                                         |
    # +----------------------------------------------------------------------+
    sub cipux_storage_get_all_values {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $cfg
            = exists $arg_r->{cfg}
            ? $self->l( $arg_r->{cfg} )
            : $self->perr('cfg');

        my $scope
            = exists $arg_r->{scope}
            ? $self->l( $arg_r->{scope} )
            : $self->perr('scope');

        my $pretty
            = exists $arg_r->{pretty}
            ? $self->l( $arg_r->{pretty} )
            : $self->perr('pretty');

        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');

        # +------------------------------------------------------------------+
        # | main
        my $storage = CipUX::Storage->new();

        my $value_hr = $storage->get_value(
            {
                scope   => $scope,
                type    => $type,
                obj     => $object,
                attr_ar => [ %{$attrvalue_hr} ]

            }
        );
        $self->_print_values(
            { scope => $scope, pretty => $pretty, value_hr => $value_hr } );

        # +------------------------------------------------------------------+
        # | API
        return;
    }

    # +----------------------------------------------------------------------+
    # | cipux_storage_set_value                                              |
    # +----------------------------------------------------------------------+
    sub cipux_storage_set_value {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $cfg
            = exists $arg_r->{cfg}
            ? $self->l( $arg_r->{cfg} )
            : $self->perr('cfg');

        my $scope
            = exists $arg_r->{scope}
            ? $self->l( $arg_r->{scope} )
            : $self->perr('scope');

        my $escope
            = exists $arg_r->{escope}
            ? $self->l( $arg_r->{escope} )
            : $self->perr('escope');

        my $changes
            = exists $arg_r->{changes}
            ? $self->l( $arg_r->{changes} )
            : $self->perr('changes');

        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 $value
            = exists $arg_r->{value}
            ? $self->l( $arg_r->{value} )
            : $self->perr('value');

        # +------------------------------------------------------------------+
        # | main
        my $storage = CipUX::Storage->new();

        my $value_hr = $storage->set_value(
            {
                scope   => $scope,    # scope referencing objects
                escope  => $escope,   # scope referencing attributes (e=erase)
                changes => $changes,
                type    => $type,
                obj     => $object,
                value   => $value,
                attr_ar => [ %{$attrvalue_hr} ]
            }
        );

        # +------------------------------------------------------------------+
        # | API
        return;

    }

    # +----------------------------------------------------------------------+
    # | cipux_storage_set_all_values                                         |
    # +----------------------------------------------------------------------+
    sub cipux_storage_set_all_values {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $cfg
            = exists $arg_r->{cfg}
            ? $self->l( $arg_r->{cfg} )
            : $self->perr('cfg');

        my $scope
            = exists $arg_r->{scope}
            ? $self->l( $arg_r->{scope} )
            : $self->perr('scope');

        my $escope
            = exists $arg_r->{escope}
            ? $self->l( $arg_r->{escope} )
            : $self->perr('escope');

        my $changes
            = exists $arg_r->{changes}
            ? $self->l( $arg_r->{changes} )
            : $self->perr('changes');

        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 $value
            = exists $arg_r->{value}
            ? $self->l( $arg_r->{value} )
            : $self->perr('value');

        # +------------------------------------------------------------------+
        # | main
        my $storage = CipUX::Storage->new();

        my $value_hr = $storage->set_value(
            {
                scope   => $scope,    # scope referencing objects
                escope  => $escope,   # scope referencing attributes (e=erase)
                changes => $changes,
                type    => $type,
                obj     => $object,
                value   => $value,
                attr_ar => [ %{$attrvalue_hr} ]
            }
        );

        # +------------------------------------------------------------------+
        # | API
        return;

    }

    # +----------------------------------------------------------------------+
    # | cipux_storage_add_node                                               |
    # +----------------------------------------------------------------------+
    sub cipux_storage_add_node {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $cfg
            = exists $arg_r->{cfg}
            ? $self->l( $arg_r->{cfg} )
            : $self->perr('cfg');

        my $object
            = exists $arg_r->{object}
            ? $self->l( $arg_r->{object} )
            : $self->perr('object');

        my $type
            = exists $arg_r->{type}
            ? $self->l( $arg_r->{type} )
            : $self->perr('type');

        # +------------------------------------------------------------------+
        # | main
        my $storage = CipUX::Storage->new();

        my %merged = ( %{$attrvalue_hr}, %{$mattrvalue_hr} );

        # If to print that out, better not relay on Data::Dumper
        # if ($debug) {
        #     my $c = Data::Dumper->new( [ \%merged ], ['*merged'] );
        #     $c->Varname('merged');
        #     $c->Purity(1);
        #     $c->Deepcopy(1);
        #     print q{=} x 56, "\n";
        #     print "\n" . $c->Dump;
        #     print q{=} x 56, "\n";
        # } ## end if($debug)

        my $value_hr = $storage->add_node(
            {
                type    => $type,
                obj     => $object,
                attr_hr => \%merged
            }
        );

        # +------------------------------------------------------------------+
        # | API
        return;
    }

    # +----------------------------------------------------------------------+
    # | cipux_storage_rename_node                                            |
    # +----------------------------------------------------------------------+
    sub cipux_storage_rename_node {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $cfg
            = exists $arg_r->{cfg}
            ? $self->l( $arg_r->{cfg} )
            : $self->perr('cfg');

        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 $value
            = exists $arg_r->{value}
            ? $self->l( $arg_r->{value} )
            : $self->perr('value');

        # +------------------------------------------------------------------+
        # | main
        my $storage = CipUX::Storage->new();

        my $value_hr = $storage->rename_node(
            {
                type  => $type,
                obj   => $object,
                value => $value
            }
        );

        # +------------------------------------------------------------------+
        # | API
        return;
    }

    # +----------------------------------------------------------------------+
    # | cipux_storage_delete_node                                            |
    # +----------------------------------------------------------------------+
    sub cipux_storage_delete_node {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $cfg
            = exists $arg_r->{cfg}
            ? $self->l( $arg_r->{cfg} )
            : $self->perr('cfg');

        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');

        # +------------------------------------------------------------------+
        # | main
        my $storage = CipUX::Storage->new();

        my $value_hr = $storage->delete_node(
            {
                type => $type,
                obj  => $object,
            }
        );

        # +------------------------------------------------------------------+
        # | API
        return;

    }

    # +----------------------------------------------------------------------+
    # | _print_values                                                        |
    # +----------------------------------------------------------------------+
    sub _print_values : PRIVATE {

        # +------------------------------------------------------------------+
        # | API
        my ( $self, $arg_r ) = @_;

        my $scope
            = exists $arg_r->{scope}
            ? $self->l( $arg_r->{scope} )
            : $self->perr('scope');

        my $pretty
            = exists $arg_r->{pretty}
            ? $self->l( $arg_r->{pretty} )
            : $self->perr('pretty');

        my $value_hr
            = exists $arg_r->{value_hr}
            ? $self->h( $arg_r->{value_hr} )
            : $self->perr('value_hr');

        # +------------------------------------------------------------------+
        # | main
        my $logger = get_logger(__PACKAGE__);
        $logger->debug('BEGIN');
        $logger->debug( 'scope: ',  $scope );
        $logger->debug( 'pretty: ', $pretty );
        $logger->debug( 'value_hr: ',
            { filter => \&Dumper, value => $value_hr } );

        if ($pretty) {

            my $mc1   = 0;    # max col ID
            my $mc2   = 0;    # max col ATTR
            my $mc3   = 0;    # max col VALUE
            my $width = 0;

            # calculate max count of attribute
            my $z = 0;        # counts attr
            foreach my $attr ( keys %{$attrvalue_hr} ) {
                $z++;         # this will count only given attr
            }

            # one OID, scope = one:
            #  l=1 => VALUE           :1 val, 1 attr, only value printed
            #  l=4 => ATTR|VALUE      :1 val, x attr, attr + value printed
            #
            # many OID, scope = all:
            #  l=2 => OID|VALUE|      :1 val, 1 attr, no need to print attr
            #  l=3 => OID|ATTR |VALUE :1 val, x attr, x oid
            #
            #  l=layout
            #
            my $layout
                = ( $z < 2 and $scope eq 'one' ) ? 1
                : ( $z < 2  and $scope eq 'all' ) ? 2
                : ( $z >= 2 and $scope eq 'all' ) ? 3
                :                                   4;    # type 4

            # count of columns
            my $col
                = ( $layout == 1 ) ? 1
                : ( $layout == 2 ) ? 2
                : ( $layout == 3 ) ? 3
                : ( $layout == 4 ) ? 2
                :                    2;

            # calculate max column width
            foreach my $oid ( sort keys %{$value_hr} ) {
                my $v = 'NULL';
                foreach my $attr ( keys %{ $value_hr->{$oid} } ) {
                    if ( defined $value_hr->{$oid}->{$attr} ) {
                        $v = join '; ', @{ $value_hr->{$oid}->{$attr} };
                    }
                    if ( $mc1 < length $oid ) {
                        $mc1 = length $oid;
                    }
                    if ( $mc2 < length $attr ) {
                        $mc2 = length $attr;
                    }
                    if ( $mc3 < length $v ) {
                        $mc3 = length $v;
                    }
                }
            }

            # col = 1 => c+2
            # col = 2 => a+c+5, b+c+5
            # col = 3 => a+b+c+8
            $width
                = ( $layout == 1 ) ? $mc3 + ( $col * 2 + $col - 1 )
                : ( $layout == 2 ) ? $mc1 + $mc3 + ( $col * 2 + $col - 1 )
                : ( $layout == 3 )
                ? $mc1 + $mc2 + $mc3 + ( $col * 2 + $col - 1 )
                : ( $layout == 4 ) ? $mc2 + $mc3 + ( $col * 2 + $col - 1 )
                :                    0;

            $logger->debug( 'ATTR  : ', $z );
            $logger->debug( 'COL   : ', $col );
            $logger->debug( 'LAYOUT: ', $layout );
            $logger->debug( 'mc1   : ', $mc1 );
            $logger->debug( 'mc2   : ', $mc2 );
            $logger->debug( 'mc3   : ', $mc3 );
            $logger->debug( 'width : ', $width );

            # print header
            print q{+} . q{-} x $width . "+\n";
            print $self->_row(
                {
                    layout => $layout,
                    pretty => $pretty,
                    value  => [ 'ID', 'ATTR', 'VALUE' ],
                    max    => [ $mc1, $mc2, $mc3 ]
                }
            );
            print q{+} . q{=} x $width . "+\n";

            foreach my $oid ( sort keys %{$value_hr} ) {
                my $v = 'NULL';
                foreach my $attr ( keys %{ $value_hr->{$oid} } ) {
                    if ( defined $value_hr->{$oid}->{$attr} ) {
                        $v = join ', ', @{ $value_hr->{$oid}->{$attr} };
                    }

                    if ( defined $attrvalue_hr->{$attr} ) {
                        print $self->_row(
                            {
                                layout => $layout,
                                max    => [ $mc1, $mc2, $mc3 ],
                                value  => [ $oid, $attr, $v ],
                                pretty => $pretty
                            }
                        );
                    }

                }
            }

            print q{+} . q{-} x $width . "+\n";
        }
        else {
            $logger->debug('Non pretty output: ');
            my $z = 0;
            foreach my $attr ( keys %{$attrvalue_hr} ) {
                $z++;    # this will count only given attr
            }
            $logger->debug( 'attr count: ', $z );
            $logger->debug( 'scope:      ', $scope );

            foreach my $oid ( sort keys %{$value_hr} ) {
                $logger->debug( 'oid: ', $oid );
                my $v = 'NULL';
                foreach my $attr ( keys %{ $value_hr->{$oid} } ) {
                    $logger->debug( 'attr:      ', $attr );

                    if ( defined $value_hr->{$oid}->{$attr} ) {
                        $v = join q{ }, @{ $value_hr->{$oid}->{$attr} };
                    }

                 #$logger->debug( 'attr2:     ',$attrvalue_hr->{$attr} ,"\n");
                 # next if not defined $attrvalue_hr->{$attr};
                    if ( $z < 2 and $scope eq 'one' )
                    {    # one value with one attribute
                        printf "%s\n", $v;
                    }
                    else {   # more the one value: (1) attr > 1 or (2) obj > 1
                        if ( $scope eq 'all' ) {

                            # do not print cn or oid line
                            # OID\tVALUE
                            if ( $z < 2 )
                            {    # with one attr, we do not have to print it
                                printf "%s\t%s\n", $oid, $v;
                            }
                            else {
                                printf "%s\t%s\t%s\n", $oid, $attr, $v;
                            }
                        }
                        else {

                            # do not print cn or oid line
                            # ATTR\tVALUE
                            printf "%s\t%s\n", $attr, $v;
                        }
                    }
                }
            }
        }

        # +------------------------------------------------------------------+
        # | API
        return;

    }

    # +======================================================================+
    # || _list_type                                                         ||
    # +======================================================================+
    sub _print_list_type : PRIVATE {

        # +------------------------------------------------------------------+
        # | 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');

        # +------------------------------------------------------------------+
        # | main
        my $storage = CipUX::Storage->new();

        my $list_ar = $storage->list_type();

        # output
        #
        #    foreach my $line (@$list_ar){
        #        chomp($line);
        #        print "$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;
            print q{+}, q{-} x $width, "+\n";
            printf '| %-' . $max_col . "s |\n", 'storage type';
            print q{+}, q{=} x $width, "+\n";
        } ## end if($pretty)

        foreach my $line ( @{$list_ar} ) {
            chomp $line;
            if ($pretty) {
                printf '| %-' . $max_col . "s |\n", $line;
            }
            else {
                print "$line\n";
            }
        } ## end foreach my $line (@$list_ar)
        if ($pretty) {
            print q{+}, q{-} x $width, "+\n";
        }

        # +------------------------------------------------------------------+
        # | API
        return;

    }

    # +======================================================================+
    # || _row                                                               ||
    # +======================================================================+
    sub _row : PRIVATE {

        # API
        my ( $self, $arg_r ) = @_;
        my $pretty      = $arg_r->{pretty} || 0;     # 0|1 pretty print
        my $layout      = $arg_r->{layout} || 2;     # layout 1..4
        my $mymaxcol_ar = $arg_r->{max}    || ();    # max colum width
        my $myvalue_ar  = $arg_r->{value}  || ();    # max colum width

        # +------------------------------------------------------------------+
        # | main
        my $logger = get_logger(__PACKAGE__);

        $logger->debug( 'pretty: ', $pretty );
        $logger->debug( 'layout: ', $layout );

        # one OID, scope = one
        #  l=1 => VALUE           :1 val, 1 attr, only value printed
        #  l=4 => ATTR| VALUE     :1 val, x attr, attr + value printed
        # many OID, scope = all
        #  l=2 => OID|VALUE|      :1 val, 1 attr, no need to print attr
        #  l=3 => OID|ATTR |VALUE :1 val, x attr, x oid
        #
        #  l=layout
        #

        my $c1 = ${ $mymaxcol_ar->[0] } || 0;
        my $c2 = ${ $mymaxcol_ar->[1] } || 0;
        my $c3 = ${ $mymaxcol_ar->[2] } || 0;
        my $v1 = ${ $myvalue_ar->[0] }  || 0;
        my $v2 = ${ $myvalue_ar->[1] }  || 0;
        my $v3 = ${ $myvalue_ar->[2] }  || 0;

        my $l = ($pretty) ? '| '  : $EMPTY_STRING;    # left border
        my $r = ($pretty) ? ' |'  : $EMPTY_STRING;    # right border
        my $m = ($pretty) ? ' | ' : $EMPTY_STRING;    # middle line

        my $v = "%-${c3}s";                           # value
        my $t = "%-${c2}s";                           # attr
        my $o = "%-${c1}s";                           # oid

        $logger->debug( 'c1: ', $c1 );
        $logger->debug( 'c2: ', $c2 );
        $logger->debug( 'c3: ', $c3 );
        $logger->debug( 'l: ',  $l );
        $logger->debug( 'r: ',  $r );
        $logger->debug( 'm: ',  $m );

        my $row
            = ( $layout == 1 ) ? sprintf( "$l$v$r", $v3 )
            : ( $layout == 2 ) ? sprintf( "$l$o$m$v$r",     $v1, $v3 )
            : ( $layout == 3 ) ? sprintf( "$l$o$m$t$m$v$r", $v1, $v2, $v3 )
            : ( $layout == 4 ) ? sprintf( "$l$o$m$v$r",     $v2, $v3 )
            :                    "$l$r";

        # +------------------------------------------------------------------+
        # | API
        return $row . "\n";

    }

}    # END INSIDE-OUT CLASS

1;

__END__

=pod

=head1 NAME

CipUX::Storage::Client - Command line client library for CipUX-Storage

=head1 VERSION

version 3.4.0.2

=head1 SYNOPSIS

 use CipUX::Storage::Client;

 my $c = CipUX::Storage::Client->new( { name => 'cipux_storage_client' } );

 $c->run();


=head1 DESCRIPTION

Provides the functions get_value, set_value to modify LDAP attribute values.
The function add_node, delete_node and rename_node for adding, deleting and
renaming LDAP objects.

=head1 SUBROUTINES/METHODS

The following functions will be exported by CipUX::Storage::Client.

=head2 new

Constructor

B<Syntax:>


  my $storage = CipUX::Storage::Client->new({});

=head2 cipux_storage_add_node

Wrapper subroutine for CipUX::Storage->add_node.

=head2 cipux_storage_delete_node

Wrapper subroutine for CipUX::Storage->delete_node.

=head2 cipux_storage_get_all_values

Wrapper subroutine for CipUX::Storage->get_all_values.

=head2 cipux_storage_get_value

Wrapper subroutine for CipUX::Storage->get_value.

=head2 cipux_storage_list

Wrapper subroutine for CipUX::Storage->print_list.

=head2 cipux_storage_rename_node

Wrapper subroutine for CipUX::Storage->rename_node.

=head2 cipux_storage_set_all_values

Wrapper subroutine for CipUX::Storage->set_all_values.

=head2 cipux_storage_set_value

Wrapper subroutine for CipUX::Storage->set_value.

=head2 run

Initialize the library. Should be caleld by a script.


=head1 CONFIGURATION AND ENVIRONMENT

See cipux-storage-access.conf and cipux-storage-structure.conf man page for
details on configuration. CipUX::Storage do not use the environment for
configuration.

=head1 DEPENDENCIES

 Carp
 Class::Std;
 CipUX
 CipUX::Storage
 Data::Dumper
 English
 Getopt::Long
 Log::Log4perl
 Pod::Usage
 Readonly

=head1 INCOMPATIBILITIES

Not known.

=head1 BUGS AND LIMITATIONS

Not known.

=head1 SEE ALSO

See the CipUX web page and the manual at L<http://www.cipux.org>

See the mailing list L<http://sympa.cipworx.org/wws/info/cipux-devel>

=head1 AUTHOR

Christian Kuelker  E<lt>christian.kuelker@cipworx.orgE<gt>

=head1 LICENSE AND COPYRIGHT

Copyright (C) 2007 - 2009 by Christian Kuelker

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

=cut