1 package MooseX::Types::Log::Dispatch;
3 use MooseX::Types -declare => [ 'LogLevel', 'Logger' ];
5 use MooseX::Types::Moose qw/Str HashRef ArrayRef/;
8 our $VERSION = '0.001000';
12 where { Log::Dispatch->level_is_valid( $_ ) },
13 message { "'$_' is not a valid Log::Dispatch log level." };
15 class_type Logger, { class => 'Log::Dispatch' };
19 via { Log::Dispatch->new( %$_ ) };
23 via { Log::Dispatch->new( @$_ ) };
32 MooseX::Types::Log::Dispatch - L<Log::Dispatch> related constraints and coercions for
38 use MooseX::Types::Log::Dispatch qw(Logger LogLevel);
46 has event_log_level => (
51 sub some_event_happened {
52 my ($self, $event) = @_;
53 $self->logger->log( level => $self->event_log_level, message => "$event happened");
56 my $obj1 = MyFoos->new(
57 event_log_level => 'debug',
58 logger => [ outputs => [ ['Screen', min_level => 'notice' ] ] ]
63 my $obj2 = MyFoos->new(
64 event_log_level => 'warning',
65 logger => { outputs => [ ['Screen', min_level => 'debug' ] ] }
68 $obj1->some_event_happened('zoom'); #nothing prints
69 $obj2->some_event_happened('zoom'); # 'zoom happened' prints
73 This module provides Moose TypeConstraints that are believed to be useful when
74 working with Log::Dispatch;
76 =head1 AVAILABLE CONSTRAINTS
80 Class type for 'Log::Dispatch' optional coercion will turn dereference an
81 array or hash reference and pass it to 'new'.
85 A subtype of 'Str', this should be a string that is a valid L<Log::Dispatch>
86 log level like: 0, 1, 2 ,3 ,4 ,5 ,6 ,7, info, debug, notice, warn, warning,
87 err, error, crit, critical, alert, emerg, and emergency
91 Guillermo Roditi (groditi) E<lt>groditi@cpan.orgE<gt>
93 =head1 COPYRIGHT AND LICENSE
95 Copyright (c) 2010 Guillermo Roditi. This program is free software; you can
96 redistribute it and/or modify it under the same terms as Perl itself.