]> git.vpit.fr Git - perl/modules/rgit.git/blob - lib/App/Rgit/Utils.pm
c081d9b99cb5ed4453abbaac78eea9b3241a7330
[perl/modules/rgit.git] / lib / App / Rgit / Utils.pm
1 package App::Rgit::Utils;
2
3 use strict;
4 use warnings;
5
6 use Cwd        (); # abs_path
7 use File::Spec (); # file_name_is_absolute, updir, splitdir, splitpath
8
9 =head1 NAME
10
11 App::Rgit::Utils - Miscellaneous utilities for App::Rgit classes.
12
13 =head1 VERSION
14
15 Version 0.08
16
17 =cut
18
19 our $VERSION = '0.08';
20
21 =head1 DESCRIPTION
22
23 Miscellaneous utilities for L<App::Rgit> classes.
24
25 This is an internal module to L<rgit>.
26
27 =head1 FUNCTIONS
28
29 =head2 C<abs_path $path>
30
31 Forcefully make a path C<$path> absolute (in L<Cwd/abs_path>'s meaning of the term) when it isn't already absolute or when it contains C<'..'>.
32
33 =cut
34
35 sub abs_path {
36  my ($path) = @_;
37
38  if (File::Spec->file_name_is_absolute($path)) {
39   my $updir  = File::Spec->updir;
40   my @chunks = File::Spec->splitdir((File::Spec->splitpath($path))[1]);
41
42   unless (grep $_ eq $updir, @chunks) {
43    return $path;
44   }
45  }
46
47  return Cwd::abs_path($path);
48 }
49
50 =head1 CONSTANTS
51
52 =head2 C<NEXT>, C<REDO>, C<LAST>, C<SAVE>
53
54 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.
55
56 =cut
57
58 use constant {
59  SAVE => 0x1,
60  NEXT => 0x2,
61  REDO => 0x4,
62  LAST => 0x8,
63 };
64
65 =head2 C<DIAG>, C<INFO>, C<WARN>, C<ERR> and C<CRIT>
66
67 Message levels.
68
69 =cut
70
71 use constant {
72  INFO => 3,
73  WARN => 2,
74  ERR  => 1,
75  CRIT => 0,
76 };
77
78 =head1 EXPORT
79
80 L<abs_path> is only exported on request.
81
82 C<NEXT> C<REDO>, C<LAST> and C<SAVE> are only exported on request, either by their name or by the C<'codes'> tags.
83
84 C<INFO>, C<WARN>, C<ERR> and C<CRIT> are only exported on request, either by their name or by the C<'levels'> tags.
85
86 =cut
87
88 use base qw/Exporter/;
89
90 our @EXPORT         = ();
91 our %EXPORT_TAGS    = (
92  funcs  => [ qw/abs_path/ ],
93  codes  => [ qw/SAVE NEXT REDO LAST/ ],
94  levels => [ qw/INFO WARN ERR CRIT/ ],
95 );
96 our @EXPORT_OK      = map { @$_ } values %EXPORT_TAGS;
97 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
98
99 =head1 SEE ALSO
100
101 L<rgit>.
102
103 =head1 AUTHOR
104
105 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
106
107 You can contact me by mail or on C<irc.perl.org> (vincent).
108
109 =head1 BUGS
110
111 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>.
112 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
113
114 =head1 SUPPORT
115
116 You can find documentation for this module with the perldoc command.
117
118     perldoc App::Rgit::Utils
119
120 =head1 COPYRIGHT & LICENSE
121
122 Copyright 2008,2009,2010 Vincent Pit, all rights reserved.
123
124 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
125
126 =cut
127
128 1; # End of App::Rgit::Utils