File Coverage

blib/lib/WebService/UK/Parliament.pm
Criterion Covered Total %
statement 14 30 46.6
branch 0 6 0.0
condition 0 3 0.0
subroutine 5 7 71.4
pod 1 1 100.0
total 20 47 42.5


line stmt bran cond sub pod time code
1             package WebService::UK::Parliament;
2              
3 1     1   57665 use 5.006;
  1         4  
4 1     1   5 use strict;
  1         2  
  1         30  
5 1     1   5 use warnings;
  1         1  
  1         47  
6              
7             our $VERSION = '0.03';
8              
9 1     1   463 use Mojo::Base -base;
  1         168099  
  1         6  
10 1     1   621 use Module::Load qw/load/;
  1         762  
  1         6  
11              
12             has instantiate => sub{ [qw/Bills CommonsVotes ErskineMay LordsVotes Members Now OralQuestions StatutoryInstruments Treaties WrittenQuestions/] };
13             has private => 0;
14              
15             has instantiated => sub { {} };
16              
17             sub new {
18 0     0 1   my $class = shift;
19 0 0 0       my $self = bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
  0 0          
20 0           for my $instant (@{ $self->instantiate }) {
  0            
21 0           my $class = sprintf "WebService::UK::Parliament::%s", $instant;
22 0           load $class;
23 0           $self->instantiated->{$instant} = $class->new( private => $self->private );
24             }
25 0           return $self;
26             }
27              
28             sub AUTOLOAD {
29 0     0     my ($self) = shift;
30 0           my $classname = ref $self;
31 0           my $validname = '[a-zA-Z][a-zA-Z0-9_]*';
32 0           our $AUTOLOAD =~ /^${classname}::($validname)$/;
33 0           my $key = $1;
34 0 0         die "illegal key name, must be of $validname form\n$AUTOLOAD" unless $key;
35 0           return $self->instantiated->{ucfirst($key)};
36             }
37              
38             1;
39              
40             __END__