File Coverage

blib/lib/App/Manoc/Manifold.pm
Criterion Covered Total %
statement 30 38 78.9
branch 1 6 16.6
condition n/a
subroutine 9 11 81.8
pod 4 4 100.0
total 44 59 74.5


line stmt bran cond sub pod time code
1             package App::Manoc::Manifold;
2             #ABSTRACT: Manifold registry
3              
4 2     2   891 use strict;
  2         4  
  2         51  
5 2     2   9 use warnings;
  2         4  
  2         68  
6              
7             our $VERSION = '2.99.2'; ##TRIAL VERSION
8              
9 2     2   377 use namespace::clean;
  2         11980  
  2         14  
10 2     2   353 use base qw(Class::Accessor::Grouped);
  2         5  
  2         933  
11 2     2   11270 use Carp qw(croak);
  2         5  
  2         82  
12              
13             use Module::Pluggable
14 2         11 sub_name => '_plugins',
15             search_path => 'App::Manoc::Manifold',
16 2     2   811 ;
  2         12426  
17 2     2   527 use Class::Load qw(load_class);
  2         8299  
  2         461  
18              
19             __PACKAGE__->mk_group_accessors( inherited => 'name_mappings' );
20             __PACKAGE__->mk_group_accessors( inherited => 'manifold_list' );
21              
22              
23              
24             sub load_namespace {
25 1     1 1 10 my $self = shift;
26 1         5 my @manifolds = $self->_plugins;
27              
28 1         3429 my %mapping;
29 1         3 foreach my $m (@manifolds) {
30             $m =~ /App::Manoc::Manifold::(.+)/ and
31 5 50       41 $mapping{$1} = $m;
32             }
33 1         29 $self->name_mappings( \%mapping );
34              
35 1         42 $self->manifold_list( \@manifolds );
36             }
37              
38              
39             sub manifolds {
40 1     1 1 925 return keys( %{ shift->name_mappings } );
  1         25  
41             }
42              
43              
44             sub new_manifold {
45 0     0 1   my $self = shift;
46 0           my $name = shift;
47              
48 0 0         defined( $self->name_mappings ) or
49             $self->load_namespace;
50              
51 0           my $mapped = $self->name_mappings->{$name};
52 0 0         $mapped or croak "Unknown manifold $name";
53              
54 0           load_class $mapped;
55 0           return $mapped->new(@_);
56             }
57              
58              
59             sub connect {
60 0     0 1   shift->new_manifold( shift, @_ )->connect();
61             }
62              
63             1;
64              
65             # Local Variables:
66             # mode: cperl
67             # indent-tabs-mode: nil
68             # cperl-indent-level: 4
69             # cperl-indent-parens-as-block: t
70             # End:
71              
72             __END__
73              
74             =pod
75              
76             =head1 NAME
77              
78             App::Manoc::Manifold - Manifold registry
79              
80             =head1 VERSION
81              
82             version 2.99.2
83              
84             =head1 METHODS
85              
86             =head2 load_namespace
87              
88             Loads all manifolds from App::Manoc::Manifold namespace
89              
90             =head2 manifolds
91              
92             Return a list of the names of all known manifolds
93              
94             =head2 new_manifold($name)
95              
96             Create a new instance of manifold $name.
97              
98             =head2 connect($name)
99              
100             Create a new instance of manifold $name and call its connect method.
101              
102             =head1 AUTHORS
103              
104             =over 4
105              
106             =item *
107              
108             Gabriele Mambrini <gmambro@cpan.org>
109              
110             =item *
111              
112             Enrico Liguori
113              
114             =back
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2017 by Gabriele Mambrini.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             =cut