line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Resource::Common; |
6
|
|
|
|
|
|
|
|
7
|
32
|
|
|
32
|
|
429
|
use v5.12.5; |
|
32
|
|
|
|
|
120
|
|
8
|
32
|
|
|
32
|
|
164
|
use warnings; |
|
32
|
|
|
|
|
65
|
|
|
32
|
|
|
|
|
1727
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
require Rex::Config; |
14
|
32
|
|
|
32
|
|
336
|
use Rex::Resource; |
|
32
|
|
|
|
|
92
|
|
|
32
|
|
|
|
|
357
|
|
15
|
32
|
|
|
32
|
|
978
|
use Data::Dumper; |
|
32
|
|
|
|
|
363
|
|
|
32
|
|
|
|
|
1900
|
|
16
|
32
|
|
|
32
|
|
237
|
use Symbol; |
|
32
|
|
|
|
|
76
|
|
|
32
|
|
|
|
|
2928
|
|
17
|
32
|
|
|
32
|
|
223
|
use base qw(Exporter); |
|
32
|
|
|
|
|
73
|
|
|
32
|
|
|
|
|
2365
|
|
18
|
32
|
|
|
32
|
|
183
|
use vars qw(@EXPORT); |
|
32
|
|
|
|
|
122
|
|
|
32
|
|
|
|
|
26998
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
@EXPORT = qw(emit resource resource_name changed created removed); |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
0
|
1841
|
sub changed { return "changed"; } |
23
|
1
|
|
|
1
|
0
|
14
|
sub created { return "created"; } |
24
|
1
|
|
|
1
|
0
|
9
|
sub removed { return "removed"; } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub emit { |
27
|
1
|
|
|
1
|
0
|
5
|
my ( $type, $message ) = @_; |
28
|
1
|
50
|
|
|
|
6
|
if ( !Rex::Resource->is_inside_resource ) { |
29
|
0
|
|
|
|
|
0
|
die "emit() only allowed inside resource."; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
50
|
|
|
18
|
$message ||= ""; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
9
|
Rex::Logger::debug( "Emiting change: " . $type . " - $message." ); |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
|
|
|
6
|
if ( $type eq changed ) { |
37
|
1
|
|
|
|
|
9
|
current_resource()->changed(1); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
50
|
|
|
|
8
|
if ( $type eq created ) { |
41
|
0
|
|
|
|
|
0
|
current_resource()->created(1); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
6
|
if ( $type eq removed ) { |
45
|
0
|
|
|
|
|
0
|
current_resource()->removed(1); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
50
|
|
|
|
23
|
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
|
436
|
my ( $name, $options, $function ) = @_; |
61
|
36
|
|
|
|
|
75
|
my $name_save = $name; |
62
|
|
|
|
|
|
|
|
63
|
36
|
|
|
|
|
89
|
my $caller_pkg = caller; |
64
|
|
|
|
|
|
|
|
65
|
36
|
100
|
|
|
|
211
|
if ( ref $options eq "CODE" ) { |
66
|
4
|
|
|
|
|
8
|
$function = $options; |
67
|
4
|
|
|
|
|
12
|
$options = {}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
36
|
50
|
|
|
|
276
|
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
|
|
|
|
|
170
|
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
|
|
|
633
|
|| ( $options->{export} ? $name : "${caller_pkg}::${name}" ) |
86
|
|
|
|
|
|
|
), |
87
|
|
|
|
|
|
|
cb => $function |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $func = sub { |
91
|
4
|
|
|
4
|
|
1899
|
$res->call(@_); |
92
|
36
|
|
|
|
|
157
|
}; |
93
|
|
|
|
|
|
|
|
94
|
36
|
50
|
33
|
|
|
726
|
if (!$class->can($name) |
95
|
|
|
|
|
|
|
&& $name_save =~ m/^[a-zA-Z_][a-zA-Z0-9_]+$/ ) |
96
|
|
|
|
|
|
|
{ |
97
|
36
|
100
|
66
|
|
|
502
|
if ( $class ne "main" && $class ne "Rex::CLI" ) { |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# if not in main namespace, register the task as a sub |
100
|
33
|
|
|
|
|
608
|
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
|
|
|
|
|
85
|
my $code = $_[-2]; |
108
|
36
|
|
|
|
|
144
|
my $ref_to_resource = qualify_to_ref( $name_save, $class ); |
109
|
36
|
|
|
|
|
934
|
*{$ref_to_resource} = $func; |
|
36
|
|
|
|
|
134
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
36
|
50
|
66
|
|
|
307
|
if ( exists $options->{export} && $options->{export} ) { |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# register in caller namespace |
115
|
32
|
|
|
|
|
143
|
my $ref_to_ISA = qualify_to_ref( 'ISA', $caller_pkg ); |
116
|
32
|
|
|
|
|
773
|
my $ref_to_EXPORT = qualify_to_ref( 'EXPORT', $caller_pkg ); |
117
|
32
|
|
|
|
|
73
|
push @{ *{$ref_to_ISA} }, "Rex::Exporter" |
|
32
|
|
|
|
|
341
|
|
118
|
32
|
50
|
|
|
|
589
|
unless ( grep { $_ eq "Rex::Exporter" } @{ *{$ref_to_ISA} } ); |
|
0
|
|
|
|
|
0
|
|
|
32
|
|
|
|
|
118
|
|
|
32
|
|
|
|
|
182
|
|
119
|
32
|
|
|
|
|
130
|
push @{ *{$ref_to_EXPORT} }, $name_save; |
|
32
|
|
|
|
|
55
|
|
|
32
|
|
|
|
|
312
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub resource_name { |
124
|
4
|
|
|
4
|
0
|
79
|
Rex::Config->set( resource_name => current_resource()->{res_name} ); |
125
|
4
|
|
|
|
|
10
|
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
|
72
|
return $Rex::Resource::CURRENT_RES[-1]; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |