home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / Results.pm < prev    next >
Encoding:
Perl POD Document  |  2002-06-14  |  3.2 KB  |  199 lines

  1. package MIME::Parser::Results;
  2.  
  3. =head1 NAME
  4.  
  5. MIME::Parser::Results - results of the last entity parsed
  6.  
  7.  
  8. =head1 SYNOPSIS
  9.  
  10. Before reading further, you should see L<MIME::Parser> to make sure that
  11. you understand where this module fits into the grand scheme of things.
  12. Go on, do it now.  I'll wait.
  13.  
  14. Ready?  Ok...
  15.  
  16.    ### Do parse, get results:
  17.    my $entity = eval { $parser->parse(\*STDIN); };
  18.    my $results  = $parser->results;
  19.  
  20.    ### Get all messages logged:
  21.    @msgs = $results->msgs;
  22.  
  23.    ### Get messages of specific types (also tests if there were problems):
  24.    $had_errors   = $results->errors;
  25.    $had_warnings = $results->warnings;
  26.  
  27.    ### Get outermost header:
  28.    $top_head  = $results->top_head;
  29.  
  30.  
  31. =head1 DESCRIPTION
  32.  
  33. Results from the last MIME::Parser parse.
  34.  
  35.  
  36. =head1 PUBLIC INTERFACE
  37.  
  38. =over 4
  39.  
  40. =cut
  41.  
  42. use strict;
  43.  
  44. ### Kit modules:
  45. use MIME::Tools qw(:msgs);
  46.  
  47.  
  48. #------------------------------
  49.  
  50. =item new
  51.  
  52. I<Constructor.>
  53.  
  54. =cut
  55.  
  56. sub new {
  57.     bless {
  58.     MPI_ID    => 'MIME-parser',
  59.     MPI_Msgs  => [],
  60.     MPI_Level => 0,
  61.     MPI_TopHead => undef,
  62.     }, shift;
  63. }
  64.  
  65. #------------------------------
  66.  
  67. =item msgs
  68.  
  69. I<Instance method.>
  70. Return all messages that we logged, in order.
  71. Every message is a string beginning with its type followed by C<": ">;
  72. the current types are C<debug>, C<warning>, and C<error>.
  73.  
  74. =cut
  75.  
  76. sub msgs { 
  77.     @{shift->{MPI_Msgs}};
  78. }
  79.  
  80. #------------------------------
  81.  
  82. =item errors
  83.  
  84. I<Instance method.>
  85. Return all error messages that we logged, in order.
  86. A convenience front-end onto msgs().
  87.  
  88. =cut
  89.  
  90. sub errors { 
  91.     grep /^error: /, @{shift->{MPI_Msgs}};
  92. }
  93.  
  94. #------------------------------
  95.  
  96. =item warnings
  97.  
  98. I<Instance method.>
  99. Return all warning messages that we logged, in order.
  100. A convenience front-end onto msgs().
  101.  
  102. =cut
  103.  
  104. sub warnings { 
  105.     grep /^warning: /, @{shift->{MPI_Msgs}};
  106. }
  107.  
  108. #------------------------------
  109.  
  110. =item top_head
  111.  
  112. I<Instance method.>
  113. Return the topmost header, if we were able to read it.
  114. This may be useful if the parse fails.
  115.  
  116. =cut
  117.  
  118. sub top_head { 
  119.     my ($self, $head) = @_;
  120.     $self->{MPI_TopHead} = $head if @_ > 1;
  121.     $self->{MPI_TopHead};
  122. }
  123.  
  124.  
  125.  
  126.  
  127. #------------------------------
  128. #
  129. # PRIVATE: FOR USE DURING PARSING ONLY!
  130. #
  131.  
  132. #------------------------------
  133. #
  134. # msg TYPE, MESSAGE...
  135. #
  136. # Take a message.
  137. #
  138. sub msg {
  139.     my $self = shift;
  140.     my $type = shift;
  141.     my @args = map { defined($_) ? $_ : '<<undef>>' } @_;
  142.  
  143.     push @{$self->{MPI_Msgs}}, ($type.": ".join('', @args)."\n");
  144. }
  145.  
  146. #------------------------------
  147. #
  148. # level [+1|-1]
  149. #
  150. # Return current parsing level.
  151. #
  152. sub level {
  153.     my ($self, $lvl) = @_;
  154.     $self->{MPI_Level} += $lvl if @_ > 1;
  155.     $self->{MPI_Level};
  156. }
  157.  
  158. #------------------------------
  159. #
  160. # indent
  161. #
  162. # Return indent for current parsing level.
  163. #
  164. sub indent {
  165.     my ($self) = @_;
  166.     '   ' x $self->{MPI_Level};
  167. }
  168.  
  169. =back
  170.  
  171. =cut
  172.  
  173. 1;
  174. __END__
  175.  
  176.  
  177. =head1 AUTHOR
  178.  
  179. Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>).
  180.  
  181. All rights reserved.  This program is free software; you can redistribute
  182. it and/or modify it under the same terms as Perl itself.
  183.  
  184.  
  185. =head1 VERSION
  186.  
  187. $Revision: 5.403 $
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.