File Coverage

blib/lib/XAS/Base.pm
Criterion Covered Total %
statement 15 52 28.8
branch 0 8 0.0
condition 0 6 0.0
subroutine 5 14 35.7
pod 1 1 100.0
total 21 81 25.9


line stmt bran cond sub pod time code
1             package XAS::Base;
2              
3             our $VERSION = '0.06';
4             our $EXCEPTION = 'XAS::Exception';
5              
6 1     1   48989 use XAS::Factory;
  1         4  
  1         11  
7 1     1   479 use XAS::Exception;
  1         1  
  1         8  
8              
9             use XAS::Class
10 1         8 debug => 0,
11             version => $VERSION,
12             base => 'Badger::Base',
13             utils => ':validation xprintf dotid',
14             import => 'class',
15             auto_can => '_auto_load',
16             vars => {
17             PARAMS => {
18             -xdebug => { optional => 1, default => 0 }
19             }
20             }
21 1     1   488 ;
  1         2  
22              
23             #use Data::Dumper;
24              
25             # ----------------------------------------------------------------------
26             # Overrides
27             # ----------------------------------------------------------------------
28              
29             class('Badger::Base')->methods(
30             message => sub {
31 0     0     my $self = shift;
32 0   0       my $name = shift
33             || $self->fatal("message() called without format name");
34              
35 0           my $m1 = XAS::Base->env->get_msgs;
36 0           my $m2 = $self->class->all_vars('MESSAGES');
37              
38 0           foreach my $h (@$m2) {
39              
40 0           while (my ($key, $value) = each(%$h)) {
41              
42 0           $m1->{$key} = $value;
43              
44             }
45              
46             }
47              
48 0           $self->class->var('MESSAGES', $m1);
49              
50 0   0       my $format = $self->class->hash_value('MESSAGES', $name)
51             || $self->fatal("message() called with invalid message type: $name");
52              
53 0           xprintf($format, @_);
54              
55             }
56             );
57              
58             # ----------------------------------------------------------------------
59             # Public Methods
60             # ----------------------------------------------------------------------
61              
62             # ----------------------------------------------------------------------
63             # Private Methods
64             # ----------------------------------------------------------------------
65              
66             sub _auto_load {
67 0     0     my $self = shift;
68 0           my $name = shift;
69              
70 0 0         if ($name eq 'alert') {
    0          
    0          
    0          
71              
72 0     0     return sub { XAS::Factory->module('alert'); }
73              
74 0           } elsif ($name eq 'email') {
75              
76 0     0     return sub { XAS::Factory->module('email'); }
77              
78 0           } elsif ($name eq 'log') {
79              
80 0     0     return sub { XAS::Factory->module('logger'); }
81              
82 0           } elsif ($name eq 'env') {
83              
84 0     0     return sub { XAS::Factory->module('environment'); }
85              
86 0           }
87              
88 0           my ($package, $filename, $line) = caller(2);
89 0           $self->throw_msg(
90             dotid($self->class) . '.auto_load.invmethod',
91             'invmethod',
92             $name, $filename, $line
93             );
94              
95             }
96              
97             sub _create_methods {
98 0     0     my $self = shift;
99 0           my $p = shift;
100              
101 1     1   3467 no strict "refs"; # to register new methods in package
  1         2  
  1         22  
102 1     1   3 no warnings; # turn off warnings
  1         1  
  1         137  
103              
104 0           while (my ($key, $value) = each(%$p)) {
105              
106 0           $self->{$key} = $value;
107              
108             *$key = sub {
109 0     0     my $self = shift;
110 0           return $self->{$key};
111 0           };
112              
113             }
114              
115             }
116              
117             sub init {
118 0     0 1   my $self = shift;
119              
120             # process PARAMS
121              
122 0           my $class = $self->class;
123 0           my $params = $self->class->hash_vars('PARAMS');
124 0           my $p = validate_params(\@_, $params, $class);
125              
126             # build our object
127              
128 0           $self->{'config'} = $p;
129 0           $self->_create_methods($p);
130              
131 0           return $self;
132              
133             }
134              
135             1;
136              
137             __END__
138              
139             =head1 NAME
140              
141             XAS::Base - The base class for the XAS environment
142              
143             =head1 SYNOPSIS
144              
145             our $VERSION = '0.01';
146              
147             use XAS::Class
148             debug => 0,
149             version => $VERSION,
150             base => 'XAS::Base',
151             vars => {
152             PARAMS => {}
153             }
154             ;
155              
156             =head1 DESCRIPTION
157              
158             This module defines a base class for the XAS Environment and inherits from
159             L<Badger::Base|https://metacpan.org/pod/Badger::Base>. The package variable $PARAMS is used to hold
160             the parameters that this class uses for initialization. Due to the pseudo
161             inheritance of package variables provided by L<Badger::Class|https://metacpan.org/pod/Badger::Class>, these
162             parameters can be changed or extended by inheriting classes. The parameters
163             are validated using L<Params::Validate|https://metacpan.org/pod/Params::Validate>. Any parameters defined in $PARAMS
164             auto-magically become accessors toward their values.
165              
166             =head1 METHODS
167              
168             =head2 new($parameters)
169              
170             This is used to initialized the class. These parameters are validated using
171             the validate_params() method.
172              
173             =head1 AUTOLOADING
174              
175             Specific modules can be auto-loaded when a method name is invoked. The
176             following methods have been defined:
177              
178             =head2 alert
179              
180             This will auto-load L<XAS::Lib::Modules::Alerts|XAS::Lib::Modules::Alerts>.
181             Please see that module for more details.
182              
183             =head2 env
184              
185             This will auto-load L<XAS::Lib::Modules::Environment|XAS::Lib::Modules::Environment>.
186             Please see that module for more details.
187              
188             =head2 email
189              
190             This will auto load L<XAS::Lib::Modules::Email|XAS::Lib::Modules::Email>.
191             Please see that module for more details.
192              
193             =head2 log
194              
195             This will auto load L<XAS::Lib::Log|XAS::Lib::Log>.
196             Please see that module for more details.
197              
198             =head1 SEE ALSO
199              
200             =over 4
201              
202             =item L<XAS|XAS>
203              
204             =back
205              
206             =head1 AUTHOR
207              
208             Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
209              
210             =head1 COPYRIGHT AND LICENSE
211              
212             Copyright (c) 2012-2015 Kevin L. Esteb
213              
214             This is free software; you can redistribute it and/or modify it under
215             the terms of the Artistic License 2.0. For details, see the full text
216             of the license at http://www.perlfoundation.org/artistic_license_2_0.
217              
218             =cut