Skip to content

Instantly share code, notes, and snippets.

@yanick
Created March 21, 2015 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanick/8d83cbc984c2bd7bc6be to your computer and use it in GitHub Desktop.
Save yanick/8d83cbc984c2bd7bc6be to your computer and use it in GitHub Desktop.
Abusing File::Serialize to the max
#!/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