STM.pm 587B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package SugarTrail::STM;
  2. # STM holder
  3. # new()
  4. # parse_headers()
  5. use strict;
  6. use warnings;
  7. use Carp;
  8. sub new {
  9. my $class = shift;
  10. my $args = { @_ };
  11. my $self = {};
  12. $self->{args} = $args;
  13. return bless $self, $class;
  14. }
  15. sub parse_headers {
  16. my $self = shift;
  17. my ($head, $body) = split "\n\n", $self->{text}, 2;
  18. my @lines = split "\n", $head;
  19. $self->{head} = $head;
  20. $self->{body} = $body;
  21. foreach (@lines) {
  22. my ($n, $v) = split ": ", $_, 2;
  23. $self->{meta}->{$n} = $v;
  24. }
  25. return scalar keys %{ $self->{meta} };
  26. }
  27. 1;