Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 5 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 20, 2013
@MidLifeXis Add plugin capability for module 224c8bb
@MidLifeXis Add plugin capability
- Allow checkdigit registry access from plugins
- Convert core A::CD registry to use new mechanism
- Add tests for plugin capability
5aefd49
Commits on Apr 21, 2013
@MidLifeXis Recommend a plugin namespace
- Suggest Algorithm::CheckDigits::Plugin:: in docs and examples
0f730ca
@MidLifeXis Branch addresses issue #1 11e354a
@MidLifeXis Update test and implementation to lc() keys 167dfe4
Showing with 117 additions and 1 deletion.
  1. +3 −0 MANIFEST
  2. +34 −1 lib/Algorithm/CheckDigits.pm
  3. +24 −0 t/MyPluginLibA.pm
  4. +24 −0 t/MyPluginLibB.pm
  5. +32 −0 t/plugin.t
View
3 MANIFEST
@@ -58,6 +58,9 @@ t/iban.t
t/imei.t
t/isbn13.t
t/nip.t
+t/MyPluginLibA.pm
+t/MyPluginLibB.pm
+t/plugin.t
t/pod-coverage.t
t/pod.t
t/script-checkdigits.t
View
35 lib/Algorithm/CheckDigits.pm
@@ -30,7 +30,16 @@ our @EXPORT = qw( CheckDigits );
use version; our $VERSION = qv('1.2.1');
-my %methods = (
+my %methods;
+sub plug_in {
+ my %new = @_;
+ while ( my ( $key, $val ) = each %new ) {
+ $methods{lc( $key )} = $val;
+ }
+ return 1;
+} # plug_in
+
+plug_in(
'mbase-001' => 'Algorithm::CheckDigits::MBase_001',
'upc' => 'Algorithm::CheckDigits::MBase_001',
'mbase-002' => 'Algorithm::CheckDigits::MBase_002',
@@ -289,6 +298,30 @@ information.
perl -MAlgorithm::CheckDigits -e Algorithm::CheckDigits::print_methods
+=head2 Algorithm::CheckDigits::plug_in()
+
+Allows another module to plug itself into the Algorithm::CheckDigits
+framework.
+
+ package Algorithm::CheckDigits::Plugin::MyPlugins;
+
+ use Algorithm::CheckDigits ();
+ Algorithm::CheckDigits::plug_in(
+ 'my_foo_check_a' => 'Algorithm::CheckDigits::Plugin::MyPlugins::Foo',
+ 'my_foo_check_b' => 'Algorithm::CheckDigits::Plugin::MyPlugins::Foo',
+ 'my_bar_check_a' => 'Algorithm::CheckDigits::Plugin::MyPlugins::Bar',
+ );
+
+Then to use them...
+
+ use Algorithm::CheckDigits;
+ use Algorithm::CheckDigits::Plugin::MyPlugins;
+
+ my $checker = CheckDigits( 'my_foo_check_a' );
+
+It is recommended to create third-party plugin modules under the
+namespace C<< Algorithm::CheckDigits::Plugin:: >>.
+
=head2 CHECK SUM METHODS
At the moment these methods to compute check digits are provided:
View
24 t/MyPluginLibA.pm
@@ -0,0 +1,24 @@
+package MyPluginLibA;
+
+use 5.006;
+use strict;
+use warnings;
+
+sub new {
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
+ return bless({}, $class);
+}
+
+sub is_valid { 1 }
+sub complete {
+ my ($self, $number) = @_;
+ return $number;
+}
+sub basenumber {
+ my ($self, $number) = @_;
+ return $number;
+}
+sub checkdigit { '' }
+
+1;
View
24 t/MyPluginLibB.pm
@@ -0,0 +1,24 @@
+package MyPluginLibB;
+
+use 5.006;
+use strict;
+use warnings;
+
+sub new {
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
+ return bless({}, $class);
+}
+
+sub is_valid { 1 }
+sub complete {
+ my ($self, $number) = @_;
+ return $number;
+}
+sub basenumber {
+ my ($self, $number) = @_;
+ return $number;
+}
+sub checkdigit { '' }
+
+1;
View
32 t/plugin.t
@@ -0,0 +1,32 @@
+use Test;
+
+use lib ( '.', 't' );
+
+use Algorithm::CheckDigits;
+
+my %tests;
+BEGIN {
+ %tests = (
+ 'plugin_test_a_a' => 'MyPluginLibA',
+ 'plugin_test_A_b' => 'MyPluginLibA',
+ 'plugin_test_b_a' => 'MyPluginLibB',
+ );
+ plan(tests => scalar(keys %tests) + 1);
+}
+Algorithm::CheckDigits::plug_in( %tests );
+
+while ( my ($name, $class) = each %tests ) {
+ my $cd = CheckDigits($name);
+ my $isa = $cd->isa( $class );
+ ok( $isa, 1, "$class ISA $name" );
+}
+
+{
+ my $name = 'plugin_test_A_b';
+ my $class = $tests{ $name };
+
+ my $cd = CheckDigits(uc($name));
+ my $isa = $cd->isa( $class );
+ ok( $isa, 1, "$class ISA $name" );
+}
+

No commit comments for this range

Something went wrong with that request. Please try again.