BalanceOfPower

 view release on metacpan or  search on metacpan

lib/BalanceOfPower/Relations/War.pm  view on Meta::CPAN

    default => "WAR"
);
has node1_faction => (
    is => 'rw',
    default => ""
);
has node2_faction => (
    is => 'rw',
    default => ""
);
has start_date => (
    is => 'ro',
    default => ""
);
has end_date => (
    is => 'rw',
    default => ""
);
has current_year => (
    is => 'rw',
    default => ""
);


sub bidirectional
{
    return 0;
}

sub print
{
    my $self = shift;
    my $army_node1 = shift;
    my $army_node2 = shift;
    return $self->output($army_node1, $army_node2, 'print');
}
sub html
{
    my $self = shift;
    my $army_node1 = shift;
    my $army_node2 = shift;
    return $self->output($army_node1, $army_node2, 'html');
}



sub output 
{
    my $self = shift;
    my $army_node1 = shift;
    my $army_node2 = shift;
    my $mode = shift;
    my $army_node1_label = $army_node1 ? "[".$army_node1."] " : "";
    my $army_node2_label = $army_node2 ? " [".$army_node2."]" : "";
    my $node1 = $army_node1_label . $self->node1;
    my $node2 = $self->node2 . $army_node2_label;
    if($mode eq 'print')
    {
        if($self->node1_faction == 0)
        {
            $node1 = color("bold") . $node1 . color("reset");
        }
        else
        {
            $node2 = color("bold") . $node2 . color("reset");
        }
        return  $node1 . " -> " . $node2;
    }
    elsif($mode eq 'html')
    {
        if($self->node1_faction == 0)
        {
            $node1 = as_html_evidenced($node1);
        }
        else
        {
            $node2 = as_html_evidenced($node2);
        }
        return  $node1 . " -> " . $node2;
    }
        
    
    
}
sub dump
{
    my $self = shift;
    my $io = shift;
    my $indent = shift || "";
    print {$io} $indent . join(";", $self->node1, $self->node2, $self->attack_leader,
                                    $self->war_id, $self->name, $self->node1_faction, $self->node2_faction, 
                                    $self->start_date, $self->end_date, $self->current_year ). "\n";
    if($self->events)
    {    
        $self->dump_events($io, $indent . " ");
    }
}
sub load
{
    my $self = shift;
    my $data = shift;
    my $war_line = ( split /\n/, $data )[0];
    $war_line =~ s/^\s+//;
    chomp $war_line;
    my ($node1, $node2, $attack_leader, $war_id, $name, $node1_faction, $node2_faction, $start_date, $end_date, $current_year) = split ";", $war_line;
    $data =~ s/^.*?\n//;
    my $events = $self->load_events($data);
    return $self->new(node1 => $node1, node2 => $node2, 
                         attack_leader => $attack_leader, 
                         war_id => $war_id, name => $name, 
                         node1_faction => $node1_faction, node2_faction => $node2_faction, 
                         start_date => $start_date, end_date => $end_date, current_year => $current_year,
                         events => $events);
}



1;



( run in 0.916 second using v1.01-cache-2.11-cpan-39bf76dae61 )