/usr/share/perl5/Autodia/Handler/dia.pm is in autodia 2.14-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 | package Autodia::Handler::dia;
require Exporter;
use strict;
=head1 NAME
Autodia::Handler::dia - AutoDia handler for dia
=head1 DESCRIPTION
This provides Autodia with the ability to read dia files, allowing you to convert them via the Diagram Export methods to images (using GraphViz and VCG) or html/xml using custom templates.
The dia handler will parse dia xml files using XML::Simple and populating the diagram object with class, superclass and package objects.
the dia handler is registered in the Autodia.pm module, which contains a hash of language names and the name of their respective language - in this case:
=head1 SYNOPSIS
use Autodia::Handler::dia;
my $handler = Autodia::Handler::dia->New(\%Config);
$handler->Parse(filename); # where filename includes full or relative path.
=head2 CONSTRUCTION METHOD
my $handler = Autodia::Handler::dia->New(\%Config);
This creates a new handler using the Configuration hash to provide rules selected at the command line.
=head2 ACCESS METHODS
$handler->Parse(filename); # where filename includes full or relative path.
This parses the named file and returns 1 if successful or 0 if the file could not be opened.
=cut
use vars qw($VERSION @ISA @EXPORT);
use Autodia::Handler;
@ISA = qw(Autodia::Handler Exporter);
use Autodia::Diagram;
use Data::Dumper;
use XML::Simple;
#---------------------------------------------------------------
#####################
# Constructor Methods
# new inherited from Autodia::Handler
#------------------------------------------------------------------------
# Access Methods
# parse_file inherited from Autodia::Handler
#-----------------------------------------------------------------------------
# Internal Methods
# _initialise inherited from Autodia::Handler
sub _parse {
my $self = shift;
my $fh = shift;
my $filename = shift;
my $Diagram = $self->{Diagram};
my $xml = XMLin(join('',<$fh>));
my %entity;
my @relationships;
# Walk the data structure based on the XML created by XML Simple
foreach my $dia_object_id ( keys %{$xml->{'dia:layer'}->{'dia:object'}} ) {
my $object = $xml->{'dia:layer'}{'dia:object'}{$dia_object_id};
my $type = $object->{type};
if (is_entity($type)) {
warn "handling entity type : $type\n";
my $name = $object->{'dia:attribute'}{name}{'dia:string'};
$name =~ s/#(.*)#/$1/;
if ($type eq 'UML - Class') {
my $Class = Autodia::Diagram::Class->new($name);
$Diagram->add_class($Class);
$entity{$dia_object_id} = $Class;
foreach my $method ( @{get_methods($object->{'dia:attribute'}{operations}{'dia:composite'})} ) {
$Class->add_operation($method);
}
foreach my $attribute (@{get_attributes($object->{'dia:attribute'}{attributes}{'dia:composite'})}){
$Class->add_attribute( $attribute );
}
} else {
my $Component = Autodia::Diagram::Component->new($name);
$Diagram->add_component($Component);
$entity{$dia_object_id} = $Component;
}
} else {
my $connection = $object->{'dia:connections'}{'dia:connection'};
warn "handling connection type : $type\n";
push (@relationships , {
from=>$connection->[0]{to},
to=> $connection->[1]{to},
type=> $type,
});
}
}
foreach my $connection ( @relationships ) {
if ($connection->{type} eq 'UML - Generalization') {
my $Inheritance = Autodia::Diagram::Inheritance->new(
$entity{$connection->{from}},
$entity{$connection->{to}},
);
$entity{$connection->{from}}->add_inheritance($Inheritance);
$entity{$connection->{to}}->add_inheritance($Inheritance);
$Diagram->add_inheritance($Inheritance);
} else {
# create new dependancy
my $Dependancy = Autodia::Diagram::Dependancy->new(
$entity{$connection->{from}},
$entity{$connection->{to}},
);
# add dependancy to diagram
$Diagram->add_dependancy($Dependancy);
# add dependancy to class
$entity{$connection->{from}}->add_dependancy($Dependancy);
# add dependancy to component
$entity{$connection->{to}}->add_dependancy($Dependancy);
}
}
}
####-----
sub is_entity {
my $object_type = shift;
my $IsEntity = 0;
$IsEntity = 1 if ($object_type =~ /(class|package)/i);
return $IsEntity;
}
sub get_methods {
my $methods = shift;
my $return = [];
my $ref = ref $methods;
if ($ref eq 'ARRAY' ) {
foreach my $method (@$methods) {
my $name = $method->{'dia:attribute'}{name}{'dia:string'};
my $type = $method->{'dia:attribute'}{type}{'dia:string'};
$name =~ s/#(.*)#/$1/g;
$type = 'void' if (ref $type);
$type =~ s/#//g;
my $arguments = get_parameters($method->{'dia:attribute'}{parameters}{'dia:composite'});
push(@$return,{name=>$name,type=>$type,Params=>$arguments, visibility=>0});
}
} elsif ($ref eq "HASH") {
my $name = $methods->{'dia:attribute'}{name}{'dia:string'};
my $type = $methods->{'dia:attribute'}{type}{'dia:string'};
$name =~ s/#(.*)#/$1/g;
$type = 'void' if (ref $type);
$type =~ s/#//g;
my $arguments = get_parameters($methods->{'dia:attribute'}{parameters}{'dia:composite'});
push(@$return,{name=>$name,type=>$type,Params=>$arguments, visibility=>0});
}
return $return;
}
sub get_parameters {
my $arguments = shift;
my $return = [];
if (ref $arguments) {
if (ref $arguments eq 'ARRAY') {
my @arguments = map (
{
Type=> $_->{'dia:attribute'}{type}{'dia:string'},
Name=> $_->{'dia:attribute'}{name}{'dia:string'},
}, @$arguments
);
foreach my $argument (@arguments) {
$argument->{Type} =~ s/#//g;
$argument->{Name} =~ s/#//g;
}
$return = \@arguments;
} else {
my $argument = { Type=>$arguments->{'dia:attribute'}{type}{'dia:string'},
Name=>$arguments->{'dia:attribute'}{name}{'dia:string'}, };
$argument->{Type} =~ s/#//g;
$argument->{Name} =~ s/#//g;
push(@$return,$argument);
}
}
return $return;
}
sub get_attributes {
my $attributes = shift;
my $ref = ref $attributes;
my $return = [];
if ($ref eq 'ARRAY') {
foreach my $attribute (@$attributes) {
my $name = $attribute->{'dia:attribute'}{name}{'dia:string'};
my $type = $attribute->{'dia:attribute'}{type}{'dia:string'};
$name =~ s/#//g;
$type =~ s/#//g;
push (@$return, {name => $name, type=> $type, visibility=>0});
}
} elsif ($ref eq 'HASH') {
my $name = $attributes->{'dia:attribute'}{name}{'dia:string'};
my $type = $attributes->{'dia:attribute'}{type}{'dia:string'};
$name =~ s/#//g;
$type =~ s/#//g;
push (@$return, {name => $name, type=> $type, visibility=>0});
}
return $return;
}
###############################################################################
=head1 SEE ALSO
Autodia::Handler
Autodia::Diagram
=head1 AUTHOR
Aaron Trevena, E<lt>aaron.trevena@gmail.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2001-2007 by Aaron Trevena
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.1 or,
at your option, any later version of Perl 5 you may have available.
=cut
1;
|