#!/usr/bin/perl use strict; use warnings; use Data::Dumper; package Event; use Moose; has 'source' => ( is => 'rw', isa => 'Str' ); has 'destination' => ( is => 'rw', isa => 'Str' ); has 'id' => ( is => 'rw', isa => 'Num' ); package LogAnalyzer; use Moose; with 'RoleDigraph'; has 'events' => ( is => 'rw', isa => 'ArrayRef' ); sub parse_line { my $self = shift; my $line = shift; chomp($line); my ($s) = $line =~ m/source:(\w+)\s*/; # we ignore the domains my ($d) = $line =~ m/destination:(\w+)\s*/; my ($id) = $line =~ m/id:(\w+)\s*/; my $event = Event->new( source => $s, destination => $d, id => $id ); push @{$self->{events}}, $event; } sub _as_queque { my $self = shift; my $queque = []; @$queque = map { [$_->source, $_->destination] } @{$self->events}; return $queque; } package main; my $al = LogAnalyzer->new; $al->parse_line($_) while (); print $al->as_digraph; __DATA__ source:joe@example.com destination:bob@example.com id:685421 source:bob@example.com destination:tim@example.com id:685424 source:joe@example.com destination:tina@example.com id:685429 source:tim@example.com destination:bob@example.com id:685431 source:tina@example.com destination:bob@example.com id:685441 source:joe@example.com destination:bob@example.com id:685452