| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OTRS::OPM::Analyzer; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Analyze OTRS add-ons (.opm files) |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
21765
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use OTRS::OPM::Analyzer::Utils::OPMFile; |
|
9
|
|
|
|
|
|
|
use OTRS::OPM::Analyzer::Utils::Config; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.03; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# define types |
|
14
|
|
|
|
|
|
|
subtype 'OPMFile' => |
|
15
|
|
|
|
|
|
|
as 'Object' => |
|
16
|
|
|
|
|
|
|
where { $_->isa( 'OTRS::OPM::Analyzer::Utils::OPMFile' ) }; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# declare attributes |
|
19
|
|
|
|
|
|
|
has opm => ( |
|
20
|
|
|
|
|
|
|
is => 'rw', |
|
21
|
|
|
|
|
|
|
isa => 'OPMFile', |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has configfile => ( |
|
25
|
|
|
|
|
|
|
is => 'ro', |
|
26
|
|
|
|
|
|
|
isa => 'Str', |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has roles => ( |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
isa => 'HashRef[ArrayRef]', |
|
32
|
|
|
|
|
|
|
default => sub { |
|
33
|
|
|
|
|
|
|
+{ |
|
34
|
|
|
|
|
|
|
file => [qw/ |
|
35
|
|
|
|
|
|
|
SystemCall |
|
36
|
|
|
|
|
|
|
PerlCritic |
|
37
|
|
|
|
|
|
|
TemplateCheck |
|
38
|
|
|
|
|
|
|
BasicXMLCheck |
|
39
|
|
|
|
|
|
|
PerlTidy |
|
40
|
|
|
|
|
|
|
/], |
|
41
|
|
|
|
|
|
|
opm => [qw/ |
|
42
|
|
|
|
|
|
|
UnitTests |
|
43
|
|
|
|
|
|
|
Documentation |
|
44
|
|
|
|
|
|
|
Dependencies |
|
45
|
|
|
|
|
|
|
License |
|
46
|
|
|
|
|
|
|
/], |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
}, |
|
49
|
|
|
|
|
|
|
auto_deref => 1, |
|
50
|
|
|
|
|
|
|
); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _load_roles { |
|
53
|
|
|
|
|
|
|
my ($self) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my %roles = $self->roles; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
for my $area ( keys %roles ) { |
|
58
|
|
|
|
|
|
|
for my $role ( @{ $roles{$area} } ) { |
|
59
|
|
|
|
|
|
|
with __PACKAGE__ . '::Role::' . $role => { |
|
60
|
|
|
|
|
|
|
-alias => { check => 'check_' . lc $role }, |
|
61
|
|
|
|
|
|
|
-excludes => 'check', |
|
62
|
|
|
|
|
|
|
}; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub analyze { |
|
68
|
|
|
|
|
|
|
my ($self,$opm) = @_; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$self->_load_roles; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $opm_object = OTRS::OPM::Analyzer::Utils::OPMFile->new( |
|
73
|
|
|
|
|
|
|
opm_file => $opm, |
|
74
|
|
|
|
|
|
|
); |
|
75
|
|
|
|
|
|
|
my $success = $opm_object->parse; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return if !$success; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->opm( $opm_object ); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my %analysis_data; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# do all the checks that are based on the content of files |
|
84
|
|
|
|
|
|
|
my %roles = $self->roles; |
|
85
|
|
|
|
|
|
|
my $counter = 1; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
for my $file ( $opm_object->files ) { |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
ROLE: |
|
90
|
|
|
|
|
|
|
for my $role ( @{ $roles{file} || [] } ) { |
|
91
|
|
|
|
|
|
|
my ($sub) = $self->can( 'check_' . lc $role ); |
|
92
|
|
|
|
|
|
|
next ROLE if !$sub; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $result = $self->$sub( $file ); |
|
95
|
|
|
|
|
|
|
my $filename = $file->{filename}; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$analysis_data{$role}->{$filename} = $result; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
last if $counter++ == 4; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# do the opm check - some checks have to be performed on the opm itself |
|
103
|
|
|
|
|
|
|
# as these checks are no checks of the content |
|
104
|
|
|
|
|
|
|
ROLE: |
|
105
|
|
|
|
|
|
|
for my $role ( @{ $roles{opm} || [] } ) { |
|
106
|
|
|
|
|
|
|
my ($sub) = $self->can( 'check_' . lc $role ); |
|
107
|
|
|
|
|
|
|
next ROLE if !$sub; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $result = $self->$sub( $opm_object ); |
|
110
|
|
|
|
|
|
|
$analysis_data{$role} = $result; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# return analysis data |
|
114
|
|
|
|
|
|
|
return \%analysis_data; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub config { |
|
118
|
|
|
|
|
|
|
my ($self) = @_; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
if ( !$self->{__config} ) { |
|
121
|
|
|
|
|
|
|
$self->{__config} = OTRS::OPM::Analyzer::Utils::Config->new( |
|
122
|
|
|
|
|
|
|
$self->configfile, |
|
123
|
|
|
|
|
|
|
); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
return $self->{__config}; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
no Moose; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=pod |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 NAME |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
OTRS::OPM::Analyzer - Analyze OTRS add-ons (.opm files) |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 VERSION |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
version 0.03 |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
use OTRS::OPM::Analyzer; |
|
148
|
|
|
|
|
|
|
use Data::Dumper; |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $opm = 'test.opm'; |
|
151
|
|
|
|
|
|
|
my $config = $FindBin::Bin . '/../conf/base.yml'; |
|
152
|
|
|
|
|
|
|
my $analyzer = OTRS::OPM::Analyzer->new( |
|
153
|
|
|
|
|
|
|
configfile => $config, |
|
154
|
|
|
|
|
|
|
roles => { |
|
155
|
|
|
|
|
|
|
opm => [qw/Dependencies/], |
|
156
|
|
|
|
|
|
|
}, |
|
157
|
|
|
|
|
|
|
); |
|
158
|
|
|
|
|
|
|
my $results = $analyzer->analyze( $opm ); |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
print Dumper $results; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
OTRS add ons are plain XML files with all information in it. Even the files that are shipped with |
|
165
|
|
|
|
|
|
|
the add on is in this XML file (base64 encoded). Those add ons should be implemented in the |
|
166
|
|
|
|
|
|
|
OTRS way of Perl programming and include some specific files (like documentation). |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 METHODS |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 analyze |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 config |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SHIPPED ROLES |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 Base |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 BasicXMLCheck |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 Dependencies |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 Documentation |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 License |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 PerlCritic |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 PerlTidy |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 SystemCall |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 TemplateCheck |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 UnitTests |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 AUTHOR |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Renee Baecker <reneeb@cpan.org> |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Renee Baecker. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This is free software, licensed under: |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |