|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
  
 
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # (c) Jan Gehring   | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #  | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Rex::Resource::Common;  | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
7
 | 
32
 | 
 
 | 
 
 | 
  
32
  
 | 
 
 | 
461
 | 
 use v5.12.5;  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
121
 | 
    | 
| 
8
 | 
32
 | 
 
 | 
 
 | 
  
32
  
 | 
 
 | 
191
 | 
 use warnings;  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
80
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1796
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '1.14.2.3'; # TRIAL VERSION  | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 require Exporter;  | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 require Rex::Config;  | 
| 
14
 | 
32
 | 
 
 | 
 
 | 
  
32
  
 | 
 
 | 
379
 | 
 use Rex::Resource;  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
79
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
388
 | 
    | 
| 
15
 | 
32
 | 
 
 | 
 
 | 
  
32
  
 | 
 
 | 
960
 | 
 use Data::Dumper;  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
112
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1739
 | 
    | 
| 
16
 | 
32
 | 
 
 | 
 
 | 
  
32
  
 | 
 
 | 
259
 | 
 use Symbol;  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
68
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2964
 | 
    | 
| 
17
 | 
32
 | 
 
 | 
 
 | 
  
32
  
 | 
 
 | 
223
 | 
 use base qw(Exporter);  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
172
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2457
 | 
    | 
| 
18
 | 
32
 | 
 
 | 
 
 | 
  
32
  
 | 
 
 | 
213
 | 
 use vars qw(@EXPORT);  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
70
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
30797
 | 
    | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 @EXPORT = qw(emit resource resource_name changed created removed);  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
0
  
 | 
1773
 | 
 sub changed { return "changed"; }  | 
| 
23
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
0
  
 | 
17
 | 
 sub created { return "created"; }  | 
| 
24
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
0
  
 | 
3
 | 
 sub removed { return "removed"; }  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub emit {  | 
| 
27
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
0
  
 | 
5
 | 
   my ( $type, $message ) = @_;  | 
| 
28
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
   if ( !Rex::Resource->is_inside_resource ) {  | 
| 
29
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     die "emit() only allowed inside resource.";  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
32
 | 
1
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
12
 | 
   $message ||= "";  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
34
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
   Rex::Logger::debug( "Emiting change: " . $type . " - $message." );  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
36
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
6
 | 
   if ( $type eq changed ) {  | 
| 
37
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
     current_resource()->changed(1);  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
40
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
6
 | 
   if ( $type eq created ) {  | 
| 
41
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     current_resource()->created(1);  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
44
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
4
 | 
   if ( $type eq removed ) {  | 
| 
45
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     current_resource()->removed(1);  | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
48
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
18
 | 
   if ($message) {  | 
| 
49
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     current_resource()->message($message);  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =over 4  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item resource($name, $function)  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub resource {  | 
| 
60
 | 
36
 | 
 
 | 
 
 | 
  
36
  
 | 
  
1
  
 | 
403
 | 
   my ( $name, $options, $function ) = @_;  | 
| 
61
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
84
 | 
   my $name_save = $name;  | 
| 
62
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
63
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
89
 | 
   my $caller_pkg = caller;  | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
65
 | 
36
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
195
 | 
   if ( ref $options eq "CODE" ) {  | 
| 
66
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     $function = $options;  | 
| 
67
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
     $options  = {};  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
70
 | 
36
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
318
 | 
   if ( $name_save !~ m/^[a-zA-Z_][a-zA-Z0-9_]+$/ ) {  | 
| 
71
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     Rex::Logger::info(  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       "Please use only the following characters for resource names:", "warn" );  | 
| 
73
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     Rex::Logger::info( "  A-Z, a-z, 0-9 and _", "warn" );  | 
| 
74
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     Rex::Logger::info( "Also the resource should start with A-Z or a-z",  | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       "warn" );  | 
| 
76
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     die "Wrong resource name syntax.";  | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
79
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
184
 | 
   my ( $class, $file, @tmp ) = caller;  | 
| 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   my $res = Rex::Resource->new(  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     type         => "${class}::$name",  | 
| 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     name         => $name,  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     display_name => (  | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       $options->{name}  | 
| 
85
 | 
36
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
708
 | 
         || ( $options->{export} ? $name : "${caller_pkg}::${name}" )  | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     ),  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     cb => $function  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   );  | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
90
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   my $func = sub {  | 
| 
91
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
 
 | 
1563
 | 
     $res->call(@_);  | 
| 
92
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
279
 | 
   };  | 
| 
93
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
94
 | 
36
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
701
 | 
   if (!$class->can($name)  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     && $name_save =~ m/^[a-zA-Z_][a-zA-Z0-9_]+$/ )  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   {  | 
| 
97
 | 
36
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
483
 | 
     if ( $class ne "main" && $class ne "Rex::CLI" ) {  | 
| 
98
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       # if not in main namespace, register the task as a sub  | 
| 
100
 | 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
678
 | 
       Rex::Logger::debug(  | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         "Registering resource (not main namespace): ${class}::$name_save");  | 
| 
102
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
103
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     else {  | 
| 
104
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
       Rex::Logger::debug("Registering resource: ${class}::$name_save");  | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
107
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
91
 | 
     my $code            = $_[-2];  | 
| 
108
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
145
 | 
     my $ref_to_resource = qualify_to_ref( $name_save, $class );  | 
| 
109
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
854
 | 
     *{$ref_to_resource} = $func;  | 
| 
 
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
167
 | 
    | 
| 
110
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
112
 | 
36
 | 
  
 50
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
285
 | 
   if ( exists $options->{export} && $options->{export} ) {  | 
| 
113
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
114
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # register in caller namespace  | 
| 
115
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
134
 | 
     my $ref_to_ISA    = qualify_to_ref( 'ISA',    $caller_pkg );  | 
| 
116
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
723
 | 
     my $ref_to_EXPORT = qualify_to_ref( 'EXPORT', $caller_pkg );  | 
| 
117
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
73
 | 
     push @{ *{$ref_to_ISA} }, "Rex::Exporter"  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
343
 | 
    | 
| 
118
 | 
32
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
600
 | 
       unless ( grep { $_ eq "Rex::Exporter" } @{ *{$ref_to_ISA} } );  | 
| 
 
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
76
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
152
 | 
    | 
| 
119
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
144
 | 
     push @{ *{$ref_to_EXPORT} }, $name_save;  | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
84
 | 
    | 
| 
 
 | 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
328
 | 
    | 
| 
120
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
123
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub resource_name {  | 
| 
124
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
  
0
  
 | 
49
 | 
   Rex::Config->set( resource_name => current_resource()->{res_name} );  | 
| 
125
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
   return current_resource()->{res_name};  | 
| 
126
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
127
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
128
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub resource_ensure {  | 
| 
129
 | 
  
0
  
 | 
 
 | 
 
 | 
  
0
  
 | 
  
0
  
 | 
0
 | 
   my ($option) = @_;  | 
| 
130
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
   $option->{ current_resource()->{res_ensure} }->();  | 
| 
131
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
132
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
133
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub current_resource {  | 
| 
134
 | 
9
 | 
 
 | 
 
 | 
  
9
  
 | 
  
0
  
 | 
70
 | 
   return $Rex::Resource::CURRENT_RES[-1];  | 
| 
135
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
136
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
137
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =back  | 
| 
138
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
139
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
140
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
141
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  |