App-Wallflower

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - the target file modification date is set according to Last-Modified

1.007 2015-11-30 BOOK
    - return a status code 999, warn, and continue processing,
      when there is a file/directory error
    - stop using PodWeaver to produce POD
    - generate META.json

1.006 2015-06-24 BOOK
    - added --errors and --verbose options to wallflower
    - added support for callbacks in App::Wallflower
      (mostly used in testing)
    - added the list of contributors to the META file
    - fixed RT #104754 files not saved in binary mode under Win32
      (thanks to Alexander Becker (ASB) and Vincent Pit (VPIT))

1.005 2015-01-24 BOOK
    - added a url attribute to declare the URL of the live application
      (thanks to Masayuki Matsuki (SONGMU) for proposing the mount, scheme
      and server_name attributes which this one replaces)
    - fixed _links_from_css to return absolute links

lib/App/Wallflower.pm  view on Meta::CPAN

    return (
        follow      => 1,
        environment => 'deployment',
        host        => ['localhost'],
        verbose     => 1,
        errors      => 1,
    );
}

# [ activating option, coderef ]
my @callbacks = (
    [
        errors => sub {
            my ( $url, $response ) = @_;
            my ( $status, $headers, $file ) = @$response;
            return if $status == 200;
            if ( $status == 301 ) {
                my $i = 0;
                $i += 2
                  while $i < @$headers && lc( $headers->[$i] ) ne 'location';
                printf "$status %s -> %s\n", $url->path, $headers->[ $i + 1 ] || '?';

lib/App/Wallflower.pm  view on Meta::CPAN

        option => \%option,
        args   => $args,
    );

}

sub new {
    my ( $class, %args ) = @_;
    my %option = ( _default_options(), %{ $args{option} || {} } );
    my $args   = $args{args} || [];
    my @cb     = @{ $args{callbacks} || [] };

    # application is required
    croak "Option application is required" if !exists $option{application};

    # setup TAP
    if ( $option{tap} ) {
        require Test::More;
        import Test::More;
        if ( $option{parallel} ) {
            my $tb = Test::Builder->new;

lib/App/Wallflower.pm  view on Meta::CPAN

        }
    }

    # --quiet = --no-verbose --no-errors
    $option{verbose} = $option{errors} = 0 if $option{quiet};

    # add the hostname passed via --url to the list built with --host
    push @{ $option{host} }, URI->new( $option{url} )->host
       if $option{url};

    # pre-defined callbacks
    push @cb, map $_->[1], grep $option{ $_->[0] }, @callbacks;

    # include option
    my $path_sep = $Config::Config{path_sep} || ';';
    $option{inc} = [ split /\Q$path_sep\E/, join $path_sep,
        @{ $option{include} || [] } ];

    local $ENV{PLACK_ENV} = $option{environment};
    local @INC = ( @{ $option{inc} }, @INC );
    my $self = {
        option     => \%option,
        args       => $args,
        callbacks  => \@cb,
        seen       => {},                # keyed on $url->path
        todo       => [],
        wallflower => Wallflower->new(
            application => ref $option{application}
                ? $option{application}
                : Plack::Util::load_psgi( $option{application} ),
            ( destination => $option{destination} )x!! $option{destination},
            ( index       => $option{index}       )x!! $option{index},
            ( url         => $option{url}         )x!! $option{url},
        ),

lib/App/Wallflower.pm  view on Meta::CPAN

    # I'm just hanging on to my friend's purse
    local $ENV{PLACK_ENV} = $self->{option}{environment};
    local @INC = ( @{ $self->{option}{inc} }, @INC );
    $self->_push_todo( @queue ? @queue : ('/') );

    while ( my $url = $self->_next_todo ) {

        # get the response
        my $response = $wallflower->get($url);

        # run the callbacks
        $_->( $url => $response ) for @{ $self->{callbacks} };

        # obtain links to resources
        my ( $status, $headers, $file ) = @$response;
        if ( ( $status == 200 || $status == 304 ) && $follow ) {
            $self->_push_todo( links_from( $response => $url ) );
        }

        # follow 301 Moved Permanently
        elsif ( $status == 301 ) {
            require HTTP::Headers;

t/35-app.t  view on Meta::CPAN

);
is( $awf, undef, "new_with_options() failed" );

# test App::Wallflower
$awf = App::Wallflower->new(
    option => {
        application => $app,
        destination => $dir,
        quiet       => 1,
    },
    callbacks => [ sub { pass('callback after running the app') } ],
);
$awf->run;

my $result = do {
    local $/;
    my $file = Path::Tiny->new( $dir, 'index.html' );
    open my $fh, '< :raw', $file or die "Can't open $file: $!";
    <$fh>;
};
is( $result, $content, "read content from file" );

t/62-modified.t  view on Meta::CPAN

    '--application' => Path::Tiny->new( t => 'test.psgi' ),
    '--destination' => Path::Tiny->tempdir,
    '--tap',
);

my $run = 0;
for ( 1 .. 2 ) {
    my $tap = TAP::Parser->new(
        {
            exec      => \@cmd,
            callbacks => {
                ALL => sub { print "    ", shift->as_string, "\n"; }
            },
        }
    );
    $tap->run;
    ok( !$tap->has_problems, "run " . ( $run + 1 ) );
    if ( !$run ) {    # first run
        ok( !$tap->skipped, 'no skip' );
    }
    else {

t/63-filter.t  view on Meta::CPAN

    '--application' => Path::Tiny->new( t => 'plain.psgi' ),
    '--destination' => Path::Tiny->tempdir,
    '--parallel' => 4,
    '--tap',
    '--filter', @URL,
);

my $tap = TAP::Parser->new(
    {
        exec      => \@cmd,
        callbacks => {
            ALL => sub { print "    ", shift->as_string, "\n"; }
        },
    }
);
$tap->run;
ok( !$tap->has_problems, 'valid TAP, all tests passed' );
ok( !$tap->skipped,      'no test skipped' );
is( $tap->tests_run, scalar @URL, 'All URL visited' );

done_testing;



( run in 0.618 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )