Dist-Zilla-Role-ErrorLogger

 view release on metacpan or  search on metacpan

lib/Dist/Zilla/Role/ErrorLogger.pm  view on Meta::CPAN

        };
        my $log_messages = sub {    # Log error messahes.
            my ( $n ) = @_;
            $self->log_error( [ '%s^^^ %s ^^^', $e, $_ ] ) for @{ $errors{ $n } };
        };
        my $log_skipped = sub {     # Log number of skipped lines.
            my ( $n ) = @_;
            if ( $n > $last + 1 ) {                 # There are skipped lines.
                my $count = $n - $last - 1;         # Number of skipped lines.
                if ( $count == 1 ) {
                    $log_line->( $n - 1 );          # There is no sense to skip one line.
                } else {
                    $self->log_error( [ '%s... skipped %d lines ...', $e, $count ] );
                };
            };
        };

        #   Do actual logging.
        $self->log_error( [ '%s:', $file->name ] );
        for my $n ( sort( { $a <=> $b } keys( %errors ) ) ) {
            $log_skipped->( $n );
            $log_line->( $n );
            $log_messages->( $n );
            $last = $n;
        };
        $log_skipped->( @$text + 1 );

    };

    if ( %invalid ) {
        $self->log_error( 'Following errors are reported against non-existing lines of the file:' );
        for my $n ( sort( { $a <=> $b } keys( %invalid ) ) ) {
            $self->log_error( [ '%s%s at %s line %d.', $t, $_, $file->name, $n ] )
                for @{ $invalid{ $n } };
        };
        return -1;
    };

    return 1;

};

# --------------------------------------------------------------------------------------------------

## no critic ( ProhibitMultiplePackages )

package Dist::Zilla::Role::ErrorLogger::Exception::Abort;

use strict;
use warnings;

## no critic ( ProhibitReusedNames )
# ABSTRACT: Exception class which C<ErrorLogger> throws to abort C<Dist::Zilla>
our $VERSION = 'v0.9.0'; # VERSION
## critic ( ProhibitReusedNames )

use overload '""' => sub { return "Aborting...\n"; };

sub throw {
    my ( $class ) = @_;
    die bless( {} => $class );          ## no critic ( RequireCarping )
};

# --------------------------------------------------------------------------------------------------

1;

# --------------------------------------------------------------------------------------------------

#pod =head1 NOTES
#pod
#pod All the methods defined in the role log items through the C<log> method. C<Dist::Zilla> takes this
#pod method from C<Log::Dispatchouli>, the latter uses C<String::Flogger> to process the messages. It
#pod means you can use C<String::Flogger> tricks, e. g.:
#pod
#pod     $self->log_error( [ 'oops at %s line %d', $file, $line ] );
#pod         #   [] are shorter than sprintf.
#pod
#pod Also note how C<Log::Dispatchouli> describes the C<log> method:
#pod
#pod     $logger->log( @messages );
#pod
#pod and says:
#pod
#pod     Each message is flogged individually, then joined with spaces.
#pod
#pod So beware. A call
#pod
#pod     $self->log_error( 'error 1', 'error 2' );
#pod
#pod logs I<one> message "error 1 error 2", I<not> I<two> messages "error 1" and "error 2", and bumps
#pod C<error_count> by 1, not 2.
#pod
#pod =head1 SEE ALSO
#pod
#pod =for :list
#pod =   L<Dist::Zilla>
#pod =   L<Dist::Zilla::Role>
#pod =   L<Dist::Zilla::Plugin>
#pod =   L<Log::Dispatchouli>
#pod =   L<String::Flogger>
#pod
#pod =head1 COPYRIGHT AND LICENSE
#pod
#pod Copyright (C) 2015 Van de Bugger
#pod
#pod License GPLv3+: The GNU General Public License version 3 or later
#pod <http://www.gnu.org/licenses/gpl-3.0.txt>.
#pod
#pod This is free software: you are free to change and redistribute it. There is
#pod NO WARRANTY, to the extent permitted by law.
#pod
#pod
#pod =cut

#   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#   file: doc/what.pod
#
#   This file is part of perl-Dist-Zilla-Role-ErrorLogger.
#

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.506 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )