File Coverage

lib/Synapse/CLI/Config/Type.pm
Criterion Covered Total %
statement 29 31 93.5
branch 1 2 50.0
condition 1 3 33.3
subroutine 8 9 88.8
pod 0 2 0.0
total 39 47 82.9


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Synapse::CLI::Config::Type
4              
5             =head1 SYNOPSIS
6              
7             my $type = Synapse::CLI::Config::Type->new ("Some::Package");
8             my $res = $type->some_class_method();
9              
10             =head1 SUMMARY
11              
12             This package is a proxy which allows manipulating package methods using an
13             object. It is used to be able to call class methods on the command line by
14             instantiating an object representing the class / package.
15              
16             For instance:
17              
18             myapp-cli type sometype some_method
19              
20              
21             =head1 EXPORTS
22              
23             none.
24              
25              
26             =head1 BUGS
27              
28             Please report them to me. Patches always welcome...
29              
30              
31             =head1 AUTHOR
32              
33             Jean-Michel Hiver, jhiver (at) synapse (dash) telecom (dot) com
34              
35             This library is free software; you can redistribute it and/or modify
36             it under the same terms as Perl itself.
37              
38             =cut
39             package Synapse::CLI::Config::Type;
40 4     4   542536 use Synapse::CLI::Config;
  4         11  
  4         112  
41 4     4   22 use warnings;
  4         8  
  4         105  
42 3     3   83 use strict;
  3         7  
  3         2102  
43              
44             our $AUTOLOAD;
45              
46              
47             sub new {
48 6     6 0 486 my $class = shift;
49 6 50       38 if (ref $class) {
50 0         0 return $class->{package}->new (@_);
51             }
52             else {
53 6         13 my $type = shift;
54 6   33     24 my $package = $Synapse::CLI::Config::ALIAS->{$type} || $type;
55 6     2   295 eval "use $package";
  2     2   778  
  1         2  
  1         10  
  2         426  
  1         2  
  1         24  
56 6         99 return bless { type => $type, package => $package }, $class;
57             }
58             }
59              
60              
61             sub can {
62 15     15 0 20 my $self = shift;
63 15         20 my $meth = shift;
64 15         161 return $self->{package}->can ($meth);
65             }
66              
67              
68             sub AUTOLOAD {
69 5     5   8 my $self = shift;
70 5         8 my $type = $self->{type};
71 5         10 my $meth = $AUTOLOAD;
72 5         27 $meth =~ s/.*:://;
73 5         26 return $self->{package}->$meth (@_);
74             }
75              
76              
77 0     0   0 sub DESTROY {
78             }
79              
80              
81             1;