File Coverage

blib/lib/SSIS/Package.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package SSIS::Package;
2              
3 1     1   24483 use 5.010;
  1         4  
  1         39  
4 1     1   6684 use Mouse;
  1         62100  
  1         8  
5              
6 1     1   1120 use XML::Simple ; #qw(:strict);
  0            
  0            
7             #use XML::LibXML;
8             use XML::CompactTree::XS;
9             use XML::LibXML::Reader;
10              
11             use Data::Dumper;
12              
13             use Carp;
14              
15             =head1 NAME
16              
17             SSIS::Package - Report on SSIS packages by Ded MedVed
18              
19             =head1 VERSION
20              
21             Version 0.04
22              
23             =cut
24              
25             our $VERSION = '0.04';
26              
27             has 'file' => (
28             is => 'rw'
29             , isa => 'Str'
30             );
31             has 'parsedssiscode' => (
32             is => 'rw'
33             );
34              
35              
36             has 'connectorsXML' => (
37             is => 'rw'
38             );
39              
40             has 'tasksXML' => (
41             is => 'rw'
42             );
43              
44             has 'connectors' => (
45             is => 'rw'
46             );
47              
48             has 'tasks' => (
49             is => 'rw'
50             );
51              
52              
53             sub BUILD {
54             my ($self) = @_;
55             } ;
56              
57             sub parse {
58              
59             local $_ ;
60              
61             my $self = shift ;
62             my $class = ref($self) || $self ;
63             my $filename = shift or croak "no filename";
64            
65             $self->file($filename);
66             $self->parsedssiscode(XMLin($filename,ForceArray => [ 'DTS:Executable', 'connections' ]));
67            
68             my $stuff = $self->parsedssiscode() ;
69              
70             #warn Dumper $stuff ;
71              
72             my @connectorsXML ;
73             foreach my $k (keys %{$stuff}) {
74             if ( $k eq 'DTS:ConnectionManager' ) {
75             foreach my $item (@{$stuff->{$k}} ) {
76             push @connectorsXML, $item ;
77             }
78             }
79             }
80             $self->connectorsXML(\@connectorsXML);
81              
82            
83             my @connectors ;
84             foreach my $conn (@connectorsXML) {
85             my @type = grep { $_->{'DTS:Name'} eq 'CreationName' } @{$conn->{'DTS:Property'}};
86             my $type = $type[0]->{'content'};
87             my $obj = SSIS::Package::ConnectionManagerFactory->make( { type => $type , properties => $conn->{'DTS:Property'} , objectData => $conn->{'DTS:ObjectData'} });
88             push @connectors, $obj;
89             }
90             $self->connectors(\@connectors);
91            
92             my @tasksXML;
93             foreach my $k (keys %{$stuff}) {
94             #warn Dumper $k, $stuff->{$k};
95             #exit;
96             if ( $k eq 'DTS:Executable' ) {
97             foreach my $item (@{$stuff->{$k}} ) {
98             push @tasksXML, $item ;
99             }
100             }
101             }
102             $self->tasksXML(\@tasksXML);
103              
104             my @tasks ;
105             foreach my $task (@tasksXML) {
106             my @connectors ;
107             $self->parse_getConnectors($task, \@connectors) ;
108              
109             my @type = grep { $_->{'DTS:Name'} eq 'CreationName' } @{$task->{'DTS:Property'}};
110             my $type = $type[0]->{'content'};
111             my $obj = SSIS::Package::DTSTaskFactory->make( { type => $task->{'DTS:ExecutableType'}, properties => $task->{'DTS:Property'}, connectors => \@connectors } );
112             push @tasks, $obj;
113             }
114             $self->tasks(\@tasks);
115            
116             }
117              
118             sub parse_getConnectors {
119              
120             local $_ ;
121              
122             my $self = shift ;
123             my $class = ref($self) || $self ;
124             my $dataTree = shift ;
125             my $return = shift ;
126            
127             if (ref($dataTree) eq 'HASH' ) {
128             foreach my $k (keys %$dataTree) {
129             if ( $k eq 'connections') {
130             push @$return, $dataTree->{$k} ;
131             }
132             else {
133             $self->parse_getConnectors($dataTree->{$k}, $return );
134             }
135             }
136             }
137             elsif (ref($dataTree) eq 'ARRAY' ) {
138             foreach my $r (@$dataTree) {
139             $self->parse_getConnectors($r,$return);
140             }
141             }
142             return ;
143            
144            
145             }
146              
147              
148              
149             __PACKAGE__->meta->make_immutable();
150              
151              
152             1;
153             __DATA__