package Post;

use strict;
use warnings;
use Data::Dumper;

  sub new{
    my $class = shift;
    my $new_post = { thread     => "",
                     postername => "",
                     postbody   => "",
                   };
    bless($new_post, $class);
    return $new_post;
  }

  sub set_post{
    my $self = shift;
    my ($thread, $poster, $text) = @_;
    $self->{thread} = $thread;
    $self->{postername} = $poster;
    $self->{postbody} = $text;
  }
  
  sub save_post{
    my $self = shift;
    my $threadfile = "$self->{thread}" . ".dat";
    my $save_string = Dumper($self);
    open (THREAD, ">> $threadfile");
    print THREAD $save_string . "\n";
    print THREAD "---\n";
  }

  sub get_post{

    my $VAR1 = ""; # reference to the post hash once it's read in.
    my $get_string = ""; # stores the post hash while it's being read in line by line.
    my $data_line = ""; # stores one line of data from the thread file.
    open THREAD, "< $threadfile";
    while ($data_line = <THREAD>){
      if($line =~ /---/){
        eval $get_string;
        return $VAR1;
      }
      $get_string = "";
      else{
        $get_string = $get_string . $data_line;
      }
    }
1;
