package Email::Moose;

use warnings;
use strict;

use Moose;
use Moose::Util::TypeConstraints;

use IO::String;

=head1 NAME

Email::Moose - Email::Simple on Moose steroids

=head1 VERSION

Version 0.01

=cut

our $VERSION = '0.01';

=head1 SYNOPSIS

    use Email::Moose;

    my $foo = Email::Moose->new();
    ...

=head1 METHODS

=head2 raw_body

=cut

subtype q{IO::String}
  => as q{Object}
  => where { $_->isa(q{IO::String}) };

coerce q{IO::String}
  => from q{Str}
    => via { IO::String->new($_) },
  => from q{ScalarRef},
    => via { IO::String->new($_) };

subtype q{IO::File}
  => as q{Object}
  => where { $_->isa(q{IO::File}) };

coerce q{IO::File}
  => from q{FileHandle}
    => via { bless $_, q{IO::File} };

=for comment
subtype q{IO::Socket}
  => as q{Object}
  => where { $_->isa(q{IO::Socket}) };

coerce q{IO::Socket}
  => from q{CodeRef}
    => via { IO::Socket->new($_) };
=cut
    
has q{raw_body} => (
  is      => q{rw},
  isa     => q{IO::String | IO::File | IO::Socket},
  coerce  => 1,
  default => sub { IO::String->new() },
);

=head2 as_string

=cut

sub as_string {
  my ($self) = @_;
  my $fh = $self->raw_body();
  return do { local $/; <$fh> };
}

=head2 import

=cut

sub import {
  my ($class, $opts) = @_;
  my $components = delete $opts->{components};
  my @roles = ();
  for my $comp (@$components){
    my $role = qq{Email::Moose::Role::} . ucfirst($comp);
    push @roles, $role;
  }

  with @roles if @roles;
}

=head2 meta

=cut

=head1 AUTHOR

Scott McWhirter, C<< <scott.mcwhirter at sophos.com> >>

=head1 BUGS

Please report any bugs or feature requests to
C<bug-email-moose at rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Email-Moose>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Email::Moose

You can also look for information at:

=over 4

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Email-Moose>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/Email-Moose>

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Email-Moose>

=item * Search CPAN

L<http://search.cpan.org/dist/Email-Moose>

=back

=head1 ACKNOWLEDGEMENTS

=head1 COPYRIGHT & LICENSE

Copyright 2006 Scott McWhirter, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1; # End of Email::Moose
