Created
March 21, 2015 17:50
-
-
Save yanick/8d83cbc984c2bd7bc6be to your computer and use it in GitHub Desktop.
Abusing File::Serialize to the max
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use File::Serialize; | |
use List::Util qw/ pairmap /; | |
use DDP; | |
my ( @parent, $tasks, $crew ); | |
transerialize_file 'omniplan/projects.xml' => [ | |
[ sub { $_->{Resources}{Resource} } => sub { +{ map { @{$_}{qw/ UID Name/} } @$_ } } => \$crew | |
], | |
[ sub { $_->{Tasks}{Task} } | |
=> sub { +{ map { | |
@parent = splice @parent, 0, $_->{OutlineLevel} - 1; | |
my $r = { | |
uid => $_->{UID}, | |
start_date => $_->{Start} =~ s/T.*$//r, | |
end_date => $_->{Finish} =~ s/T.*$//r, | |
label => $_->{Name}, | |
done => !$_->{Active}, | |
parent => $parent[-1], | |
}; | |
push @parent, $r->{uid}; | |
$r->{uid} => $r; | |
} @$_ } } | |
=> \$tasks | |
], | |
[ sub { push @{$tasks->{$_->{parent}}{subtasks}}, $_->{uid} | |
for grep { $_->{parent} and $_->{parent} != $_->{uid} } values $tasks; } | |
], | |
[ | |
sub { $_->{Assignments}{Assignment} } | |
=> sub { | |
pairmap { push @{ $tasks->{$a}{crew} }, $crew->{$b} } | |
map { @{$_}{ qw/ TaskUID ResourceUID / } } | |
@$_ | |
} | |
], | |
]; | |
p $tasks; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment