-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFlash.pm
84 lines (56 loc) · 1.75 KB
/
Flash.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package Datahub::Factory::Flash;
use Datahub::Factory::Sane;
our $VERSION = '1.77';
use Moo::Role;
use MooX::Aliases;
use Term::ANSIColor qw(:constants);
use namespace::clean;
has verbose => ( is => 'rw' );
sub info {
my ($self, $msg) = @_;
if (defined $self->verbose) {
local $Term::ANSIColor::AUTORESET = 1;
say YELLOW, $msg;
}
}
sub error {
my ($self, $msg) = @_;
if (defined $self->verbose) {
local $Term::ANSIColor::AUTORESET = 1;
say BRIGHT_RED, "\x{2716} - $msg";
}
}
sub success {
my ($self, $msg) = @_;
if (defined $self->verbose) {
local $Term::ANSIColor::AUTORESET = 1;
say BRIGHT_GREEN, "\x{2714} - $msg";
}
}
1;
__END__
=head1 NAME
Datahub::Factory::Flash - Pretty verbose flash messages
=head1 DESCRIPTION
Output pretty verbose messages on the command line interface.
=head1 USAGE
The C<verbose> flag is a boolean used to enables or disable the output fo messages. Messages will be outputed by default to STDOUT. This module currently supports three types of messages C<info>, C<error> and C<success>. The ouput is styled using L<Term::ANSIColor>.
This package is a L<Moo::Role>.
For example, consider this module:
package Datahub::Factory::Foo;
use Moo;
with 'Datahub::Factory::Flash';
sub messaging {
$self->{verbose} = 1;
$self->info("An info message");
$self->error("An error message");
$self->success("A success message");
}
=head1 AUTHORS
Matthias Vandermaesen <matthias.vandermaesen@vlaamsekunstcollectie.be>
=head1 COPYRIGHT
Copyright 2016 - PACKED vzw, Vlaamse Kunstcollectie vzw
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the terms of the GPLv3.
=cut