]> git.vpit.fr Git - perl/modules/rgit.git/blob - lib/App/Rgit/Utils.pm
7a4c3b36779a8a4aef2e3949544f8ff5e26d6c57
[perl/modules/rgit.git] / lib / App / Rgit / Utils.pm
1 package App::Rgit::Utils;
2
3 use strict;
4 use warnings;
5
6 use Carp qw/croak/;
7
8 =head1 NAME
9
10 App::Rgit::Utils - Miscellaneous utilities for App::Rgit classes.
11
12 =head1 VERSION
13
14 Version 0.06
15
16 =cut
17
18 our $VERSION = '0.06';
19
20 =head1 DESCRIPTION
21
22 Miscellaneous utilities for L<App::Rgit> classes.
23
24 This is an internal module to L<rgit>.
25
26 =head1 CONSTANTS
27
28 =head2 C<NEXT>, C<REDO>, C<LAST>, C<SAVE>
29
30 Codes to return from the C<report> callback to respectively proceed to the next repository, retry the current one, end it all, and save the return code.
31
32 =cut
33
34 use constant {
35  SAVE => 0x1,
36  NEXT => 0x2,
37  REDO => 0x4,
38  LAST => 0x8,
39 };
40
41 =head2 C<DIAG>, C<INFO>, C<WARN>, C<ERR> and C<CRIT>
42
43 Message levels.
44
45 =cut
46
47 use constant {
48  INFO => 3,
49  WARN => 2,
50  ERR  => 1,
51  CRIT => 0,
52 };
53
54 =head1 FUNCTIONS
55
56 =head2 C<validate @method_args>
57
58 Sanitize arguments passed to methods.
59
60 =cut
61
62 sub validate {
63  my $class = shift;
64  croak 'Optional arguments must be passed as key/value pairs' if @_ % 2;
65  $class = ref($class) || $class;
66  $class = caller unless $class;
67  return $class, @_;
68 }
69
70 =head1 EXPORT
71
72 C<validate> is only exported on request, either by its name or by the C<'funcs'> tag.
73
74 C<NEXT> C<REDO>, C<LAST> and C<SAVE> are only exported on request, either by their name or by the C<'codes'> tags.
75
76 C<INFO>, C<WARN>, C<ERR> and C<CRIT> are only exported on request, either by their name or by the C<'levels'> tags.
77
78 =cut
79
80 use base qw/Exporter/;
81
82 our @EXPORT         = ();
83 our %EXPORT_TAGS    = (
84  funcs  => [ qw/validate/ ],
85  codes  => [ qw/SAVE NEXT REDO LAST/ ],
86  levels => [ qw/INFO WARN ERR CRIT/ ],
87 );
88 our @EXPORT_OK      = map { @$_ } values %EXPORT_TAGS;
89 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
90
91 =head1 SEE ALSO
92
93 L<rgit>.
94
95 =head1 AUTHOR
96
97 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
98
99 You can contact me by mail or on C<irc.perl.org> (vincent).
100
101 =head1 BUGS
102
103 Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>.  I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
104
105 =head1 SUPPORT
106
107 You can find documentation for this module with the perldoc command.
108
109     perldoc App::Rgit::Utils
110
111 =head1 COPYRIGHT & LICENSE
112
113 Copyright 2008-2009 Vincent Pit, all rights reserved.
114
115 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
116
117 =cut
118
119 1; # End of App::Rgit::Utils