Permalink
Browse files

using Module::Pluggable

  • Loading branch information...
1 parent a27510b commit c17864bd311a7ae4b98b053d029287e92d2dc195 Zbigniew Lukasiak committed Sep 1, 2011
View
@@ -2,20 +2,14 @@ use strict;
use warnings;
package Courriel::MMS;
-use namespace::autoclean;
+# use namespace::autoclean;
+# unfortunately autoclean does not work with Module::Pluggable
use Moose;
extends 'Courriel';
use MIME::Types;
-use Class::MOP;
-
-my @subclasses = qw(
-Courriel::MMS::MymtsRu
-Courriel::MMS::TmobileUK
-Courriel::MMS::TmobileUS
-Courriel::MMS::SprintUS
-);
+use Module::Pluggable require => 1;
# --- Attributes ---
@@ -30,23 +24,12 @@ around 'parse' => sub {
my $self = shift;
my $email = $self->$orig( @_ );
- for my $class ( @subclasses ){
- Class::MOP::load_class( $class );
+ for my $class ( $email->plugins ){
return bless( $email, $class ) if $class->match( $email );
}
return $email;
};
-# sub parse {
-# my $class = shift;
-# my $email = $class->SUPER::parse( @_ );
-# if ( $email->from =~ /mms\.mymts\.ru/i ){
-# require Courriel::MMS::MymtsRu;
-# return bless( $email, 'Courriel::MMS::MymtsRu' );
-# }
-# return $email;
-# }
-
# --- Instance methods ---
sub _get_image_parts {
@@ -113,11 +96,7 @@ __PACKAGE__->meta()->make_immutable();
__END__
-=pod
-
-=head1 NAME
-
-Courriel::MMS - L<Courriel> extension for dealing with MMS messages
+# ABSTRACT: L<Courriel> extension for dealing with MMS messages
=head1 SYNOPSIS
@@ -1,7 +1,7 @@
use strict;
use warnings;
-package Courriel::MMS::MymtsRu;
+package Courriel::MMS::Plugin::MymtsRu;
use namespace::autoclean;
use Moose;
@@ -35,11 +35,7 @@ __PACKAGE__->meta()->make_immutable();
__END__
-=pod
-
-=head1 NAME
-
-Courriel::MMS::MymtsRu - L<Courriel> extension for dealing with MMS messages from mms.mymts.ru
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from mms.mymts.ru
=head1 SYNOPSIS
@@ -1,7 +1,7 @@
use strict;
use warnings;
-package Courriel::MMS::SprintUS;
+package Courriel::MMS::Plugin::SprintUS;
use namespace::autoclean;
use Moose;
use WWW::Mechanize;
@@ -87,11 +87,7 @@ __PACKAGE__->meta()->make_immutable();
__END__
-=pod
-
-=head1 NAME
-
-Courriel::MMS::SprintUS - L<Courriel> extension for dealing with MMS messages from Sprint US.
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from Sprint US.
=head1 SYNOPSIS
@@ -1,7 +1,7 @@
use strict;
use warnings;
-package Courriel::MMS::TmobileUK;
+package Courriel::MMS::Plugin::TmobileUK;
use namespace::autoclean;
use Moose;
@@ -33,11 +33,7 @@ __PACKAGE__->meta()->make_immutable();
__END__
-=pod
-
-=head1 NAME
-
-Courriel::MMS::TmobileUK - L<Courriel> extension for dealing with MMS messages from T-mobile UK
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from T-mobile UK
=head1 SYNOPSIS
@@ -1,7 +1,7 @@
use strict;
use warnings;
-package Courriel::MMS::TmobileUS;
+package Courriel::MMS::Plugin::TmobileUS;
use namespace::autoclean;
use Moose;
@@ -33,11 +33,7 @@ __PACKAGE__->meta()->make_immutable();
__END__
-=pod
-
-=head1 NAME
-
-Courriel::MMS::TmobileUS - L<Courriel> extension for dealing with MMS messages from T-mobile US
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from T-mobile US
=head1 SYNOPSIS
View
@@ -9,7 +9,7 @@ use File::Slurp 'slurp';
my $email = Courriel::MMS->parse( text => scalar( slurp( 't/data/MymtsRu.eml' ) ) );
-isa_ok( $email, 'Courriel::MMS::MymtsRu', 'MMS from mms.mymts.ru' );
+isa_ok( $email, 'Courriel::MMS::Plugin::MymtsRu', 'MMS from mms.mymts.ru' );
my @images = $email->get_mms_images;
is( scalar( @images ), 1, 'Logo filtered out' );
@@ -24,7 +24,7 @@ my $c_email = build_email(
attach( file => 't/data/cool.gif', filename => 'masthead.gif' ),
);
$email = Courriel::MMS->parse( text => $c_email->as_string );
-isa_ok( $email, 'Courriel::MMS::TmobileUS', 'MMS from tmomail.net' );
+isa_ok( $email, 'Courriel::MMS::Plugin::TmobileUS', 'MMS from tmomail.net' );
@images = $email->get_mms_images;
is( scalar( @images ), 0, 'Logo filtered out' );
@@ -35,7 +35,7 @@ $c_email = build_email(
plain_body( 'test' ),
);
$email = Courriel::MMS->parse( text => $c_email->as_string );
-isa_ok( $email, 'Courriel::MMS::SprintUS', 'MMS from sprint' );
+isa_ok( $email, 'Courriel::MMS::Plugin::SprintUS', 'MMS from sprint' );

0 comments on commit c17864b

Please sign in to comment.