Changeset 5

Show
Ignore:
Timestamp:
05/16/05 15:44:37 (3 years ago)
Author:
evdb
Message:

Changed: ran through perltidy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Scrpbk.pm

    r4 r5  
    1313# Get the config. 
    1414my $yaml_file = -e 'setup.yaml' ? 'setup.yaml' : '../setup.yaml'; 
    15 my $yaml_config = YAML::LoadFile( $yaml_file
    16     || die "Could not load the setup file"; 
     15my $yaml_config = YAML::LoadFile($yaml_file
     16  || die "Could not load the setup file"; 
    1717Scrpbk->config( name => 'Scrpbk', %$yaml_config ); 
    1818Scrpbk->setup; 
     
    2626    # Load user from cookie 
    2727    $c->forward('load_session_from_cookie') 
    28        if $c->req->cookies->{session}; 
     28      if $c->req->cookies->{session}; 
    2929 
    3030} 
     
    3535 
    3636    # Get user 'homepage' onto stash as 'target'. 
    37     $c->stash->{target} = Scrpbk::M::Person->retrieve 
    38         ( tag => 'homepage' ) 
    39         || warn "Could not load user 'homepage'"; 
     37    $c->stash->{target} = Scrpbk::M::Person->retrieve( tag => 'homepage' ) 
     38      || warn "Could not load user 'homepage'"; 
    4039} 
    4140 
     
    4544    # If there is a redirect going change the template. 
    4645    if ( $c->res->redirect ) { 
    47        $c->stash->{template} = 'redirect'; 
     46        $c->stash->{template} = 'redirect'; 
    4847    } 
    4948 
     
    5453    my ( $self, $c ) = @_; 
    5554    my $token = $c->req->cookies->{session}->value 
    56        || return 0; 
     55      || return 0; 
    5756 
    58     my $session = Scrpbk::M::Session->retrieve( $token
    59        || return 0; 
     57    my $session = Scrpbk::M::Session->retrieve($token
     58      || return 0; 
    6059 
    6160    # Update the last visit tag. 
     
    6867    return 1; 
    6968} 
    70  
    7169 
    7270################################################################################ 
     
    8179    my $me = URI->new( 'http://' . $c->config->{http_host} ); 
    8280    $me->path( $c->req->path ); 
    83     $me->query_form( %{$c->req->parameters} ); 
     81    $me->query_form( %{ $c->req->parameters } ); 
    8482 
    8583    # Create the login URI. 
    8684    my $login = URI->new( 'http://' . $c->config->{http_host} ); 
    87     $login->path( '/person/login' ); 
     85    $login->path('/person/login'); 
    8886    $login->query_form( redirect_to => $me->as_string ); 
    8987 
     
    122120 
    123121    # If there is no referer send to users homepage or site homepage 
    124     unless ( $referer ) { 
    125        my $person = $c->stash->{person}; 
    126         $referer ||= $person ? 
    127             '/~' . $person->tag : 
    128           '/'; 
     122    unless ($referer) { 
     123        my $person = $c->stash->{person}; 
     124        $referer ||= $person 
     125          ? '/~' . $person->tag 
     126          : '/'; 
    129127    } 
    130128 
    131     $c->res->redirect( $referer ); 
     129    $c->res->redirect($referer); 
    132130    return 0; 
    133131} 
  • trunk/lib/Scrpbk/C/Holder.pm

    r2 r5  
    1010    # Redirect to login unless we have a user. 
    1111    unless ( $c->stash->{person} ) { 
    12        $c->forward('/redirect_to_login'); 
    13        return 0; 
     12        $c->forward('/redirect_to_login'); 
     13        return 0; 
    1414    } 
    1515} 
     
    3333    my $person = $c->stash->{person} || return 0; 
    3434 
    35     my $holder = Scrpbk::M::Holder->retrieve 
    36         ( id     => $holder_id, 
    37           person => $person ); 
     35    my $holder = Scrpbk::M::Holder->retrieve( 
     36        id     => $holder_id, 
     37        person => $person 
     38    ); 
    3839 
    39     unless ( $holder ) { 
    40        $c->stash->{fatal_error} = "Could not retrieve holder '$holder_id'."; 
    41        return $c->forward('/fatal_error'); 
     40    unless ($holder) { 
     41        $c->stash->{fatal_error} = "Could not retrieve holder '$holder_id'."; 
     42        return $c->forward('/fatal_error'); 
    4243    } 
    4344 
     
    5960    $direction =~ s/[^a-z]//g; 
    6061 
    61     my %directions = map {$_=>1} qw(up down left right); 
     62    my %directions = map { $_ => 1 } qw(up down left right); 
    6263 
    6364    # Check that the direction is valid. 
    64     unless ( $directions{ $direction } ) { 
    65        $c->stash->{fatal_error} = "Cannot move in direction '$direction'."; 
    66        return $c->forward('/fatal_error'); 
     65    unless ( $directions{$direction} ) { 
     66        $c->stash->{fatal_error} = "Cannot move in direction '$direction'."; 
     67        return $c->forward('/fatal_error'); 
    6768    } 
    6869 
    69     my $holder = Scrpbk::M::Holder->retrieve 
    70         ( id     => $holder_id, 
    71           person => $person ); 
     70    my $holder = Scrpbk::M::Holder->retrieve( 
     71        id     => $holder_id, 
     72        person => $person 
     73    ); 
    7274 
    73     unless ( $holder ) { 
    74        $c->stash->{fatal_error} = "Could not load the holder '$holder_id'."; 
    75        return $c->forward('/fatal_error'); 
     75    unless ($holder) { 
     76        $c->stash->{fatal_error} = "Could not load the holder '$holder_id'."; 
     77        return $c->forward('/fatal_error'); 
    7678    } 
    77      
    78     $holder->relocate( $direction ); 
     79 
     80    $holder->relocate($direction); 
    7981 
    8082    return $c->forward('/redirect_to_referer'); 
     
    9193 
    9294    my $holder = undef; 
    93      
     95 
    9496    if ( $holder_id eq 'new' ) { 
    95         # Don't do anything. 
    96         $holder = undef; 
    9797 
    98     } elsif ( $holder_id =~ m/^\d+$/ ) { 
    99         # Try to load the holder. 
    100         $holder = Scrpbk::M::Holder->retrieve 
    101             ( id     => $holder_id, 
    102               person => $person ); 
     98        # Don't do anything. 
     99        $holder = undef; 
    103100 
    104         unless ( $holder ) { 
    105             # Error loading the holder. 
    106             $c->stash->{fatal_error} = "Holder '$holder_id' not found."; 
    107             return $c->forward('/fatal_error'); 
    108         } 
     101    } 
     102    elsif ( $holder_id =~ m/^\d+$/ ) { 
    109103 
    110     } else { 
    111         # Should not be here. 
    112         $c->stash->{fatal_error} = "Can't get the holder '$holder_id'."; 
    113         return $c->forward('/fatal_error'); 
     104        # Try to load the holder. 
     105        $holder = Scrpbk::M::Holder->retrieve( 
     106            id     => $holder_id, 
     107            person => $person 
     108        ); 
     109 
     110        unless ($holder) { 
     111 
     112            # Error loading the holder. 
     113            $c->stash->{fatal_error} = "Holder '$holder_id' not found."; 
     114            return $c->forward('/fatal_error'); 
     115        } 
     116 
     117    } 
     118    else { 
     119 
     120        # Should not be here. 
     121        $c->stash->{fatal_error} = "Can't get the holder '$holder_id'."; 
     122        return $c->forward('/fatal_error'); 
    114123    } 
    115124 
    116125    # Give the holder to the stash. 
    117126    $c->stash->{holder} = $holder; 
    118      
     127 
    119128    # Is there a form to do. 
    120129    return unless $c->req->param('form_submitted'); 
     
    127136    my @messages = (); 
    128137    push @messages, "The name is too long, must be no more than than 40 chars" 
    129        if length( $name ) > 40; 
     138      if length($name) > 40; 
    130139    push @messages, "The name is too short, must be at least 1 char" 
    131        if length( $name ) < 1; 
     140      if length($name) < 1; 
    132141 
    133142    # Return if errors found. 
    134143    if ( scalar @messages ) { 
    135        $c->stash->{messages} = \@messages; 
    136        $c->stash->{new} = {name => $name}; 
    137        return 1
     144        $c->stash->{messages} = \@messages; 
     145        $c->stash->{new} = { name => $name }; 
     146        return 1
    138147    } 
    139148 
    140149    # Update or create the holder. 
    141     if ( $holder ) { 
    142         $holder->name( $name ); 
    143         $holder->update; 
    144     } else { 
    145         $holder = Scrpbk::M::Holder->create 
    146             ({ person => $person, name   => $name }); 
     150    if ($holder) { 
     151        $holder->name($name); 
     152        $holder->update; 
     153    } 
     154    else { 
     155        $holder = 
     156          Scrpbk::M::Holder->create( { person => $person, name => $name } ); 
    147157    } 
    148158    $holder->rerank_column; 
  • trunk/lib/Scrpbk/C/Person.pm

    r2 r5  
    3737 
    3838    # Get the tag and password. 
    39     my $tag      = lc($c->req->param('tag')) || ''; 
    40     my $password = $c->req->param('password') || ''; 
     39    my $tag      = lc( $c->req->param('tag') ) || ''; 
     40    my $password = $c->req->param('password') || ''; 
    4141 
    4242    # Try to load the person. 
    43     my $person = Scrpbk::M::Person->retrieve 
    44        ( tag => $tag, password => $password ); 
    45      
     43    my $person = 
     44      Scrpbk::M::Person->retrieve( tag => $tag, password => $password ); 
     45 
    4646    # We have a person - do what is needed and return. 
    47     if ( $person ) { 
    48         $c->stash->{person} = $person; 
    49         $c->forward( 'create_session' ); 
    50         $c->res->redirect( $redirect_to ||  
    51                            $c->req->referer() ||  
    52                            '/~' . $person->tag 
    53                          ); 
    54         return 1; 
    55     } 
    56  
    57     $c->stash->{messages} =  
    58         ["Could not log you in. Please check your details are correct."]; 
     47    if ($person) { 
     48        $c->stash->{person} = $person; 
     49        $c->forward('create_session'); 
     50        $c->res->redirect( $redirect_to 
     51              || $c->req->referer() 
     52              || '/~' . $person->tag ); 
     53        return 1; 
     54    } 
     55 
     56    $c->stash->{messages} = 
     57      ["Could not log you in. Please check your details are correct."]; 
    5958 
    6059    return 1; 
     
    7675    # Unless a form has been submitted return. 
    7776    return 1 unless $c->req->param('form_submitted'); 
    78          
     77 
    7978    # Get the values. 
    8079    my $tag       = $c->req->param('tag')       || ''; 
     
    8281    my $password  = $c->req->param('password')  || ''; 
    8382    my $password2 = $c->req->param('password2') || ''; 
    84      
     83 
    8584    # Do some simple tidying up on the tag. 
    8685    $tag =~ lc $tag; 
     
    8887 
    8988    # If both passwords are empty generate a random one to use. 
    90     unless ( length( $password ) || length( $password )) { 
    91        my @chars = ( 'a'..'z', 'A'..'Z' ); 
    92        my $tmp = ''; 
    93        $tmp .= $chars[ rand scalar @chars ] for 1..9; 
    94        $password = $password2 = $tmp; 
    95     } 
    96               
     89    unless ( length($password) || length($password) ) { 
     90        my @chars = ( 'a' .. 'z', 'A' .. 'Z' ); 
     91        my $tmp = ''; 
     92        $tmp .= $chars[ rand scalar @chars ] for 1 .. 9; 
     93        $password = $password2 = $tmp; 
     94    } 
     95 
    9796    # Errors will go on here. 
    9897    my @messages = (); 
     
    10099    # Check that the tag is long enough. 
    101100    unless ( length($tag) >= 4 && length($tag) <= 20 ) { 
    102        push @messages, "The tag must be 4 to 20 characters long."; 
     101        push @messages, "The tag must be 4 to 20 characters long."; 
    103102    } 
    104103 
    105104    # Check that the tag is correct. 
    106105    if ( $tag =~ m/[^a-z]/ ) { 
    107        push @messages, "The tag must be compased of letters 'a' to 'z'  only."; 
     106        push @messages, "The tag must be compased of letters 'a' to 'z'  only."; 
    108107    } 
    109108 
    110109    # Check that the tag is not already taken. 
    111110    if ( Scrpbk::M::Person->retrieve( tag => $tag ) ) { 
    112        push @messages, "The tag '$tag' is already taken - please try another."; 
     111        push @messages, "The tag '$tag' is already taken - please try another."; 
    113112    } 
    114113 
    115114    # Check the email address is valid. 
    116     my $valid_email = Email::Valid->address( $email ); 
    117     unless ( $valid_email ) { 
    118        push @messages, "The email address was not valid, please check it."; 
    119     } 
    120      
     115    my $valid_email = Email::Valid->address($email); 
     116    unless ($valid_email) { 
     117        push @messages, "The email address was not valid, please check it."; 
     118    } 
     119 
    121120    # Check that the email address is not already used. 
    122121    if ( Scrpbk::M::Person->retrieve( email => $valid_email ) ) { 
    123        push @messages, "The email address is already being used."; 
     122        push @messages, "The email address is already being used."; 
    124123    } 
    125124 
    126125    # Check that the email address is not too long. 
    127     if ( length( $valid_email ) >= 120 ) { 
    128         push @messages, "The email address cannot be longer than 120 characters."; 
    129 }  
     126    if ( length($valid_email) >= 120 ) { 
     127        push @messages, 
     128          "The email address cannot be longer than 120 characters."; 
     129    } 
    130130 
    131131    # Check that the passwords are long enough. 
    132132    unless ( length($password) >= 6 && length($password) <= 20 ) { 
    133        push @messages, "The password must be 6 to 20 characters long."; 
     133        push @messages, "The password must be 6 to 20 characters long."; 
    134134    } 
    135135 
    136136    # Check the passwords match. 
    137137    unless ( $password eq $password2 ) { 
    138        push @messages, "The passswords do not match."; 
     138        push @messages, "The passswords do not match."; 
    139139    } 
    140140 
    141141    # If there are any messages then there is a problem. 
    142142    if ( scalar @messages ) { 
    143         $c->stash->{messages} = \@messages; 
    144         $c->stash->{details} = { tag      => $tag, 
    145                                  email    => $email, 
    146                                  password => $password, 
    147                                  password2 => $password2 }; 
    148         return 1; 
     143        $c->stash->{messages} = \@messages; 
     144        $c->stash->{details}  = { 
     145            tag       => $tag, 
     146            email     => $email, 
     147            password  => $password, 
     148            password2 => $password2 
     149        }; 
     150        return 1; 
    149151    } 
    150152 
    151153    # Create the account. 
    152     my $person = Scrpbk::M::Person->create 
    153         ({ tag      => $tag, 
    154            email    => $valid_email, 
    155            password => $password }); 
     154    my $person = Scrpbk::M::Person->create( 
     155        { 
     156            tag      => $tag, 
     157            email    => $valid_email, 
     158            password => $password 
     159        } 
     160    ); 
    156161 
    157162    # Did we create a user? 
    158     unless ( $person ) { 
    159        $c->stash->{fatal_error} = "Could not create the user."; 
    160        return $c->forward('/fatal_error'); 
    161     } 
    162      
     163    unless ($person) { 
     164        $c->stash->{fatal_error} = "Could not create the user."; 
     165        return $c->forward('/fatal_error'); 
     166    } 
     167 
    163168    # Put the person on the template. 
    164169    $c->stash->{person} = $person; 
     
    166171    # send an email with account details. 
    167172    $c->stash->{email_template} = 'emails/new_account'; 
    168     $c->stash->{email_to} = $person->email; 
    169     $c->stash->{email_bcc} = 'scrpbk@ecclestoad.co.uk'; 
     173    $c->stash->{email_to}       = $person->email; 
     174    $c->stash->{email_bcc}      = 'scrpbk@ecclestoad.co.uk'; 
    170175    $c->forward("Scrpbk::V::Email"); 
    171176 
    172177    # Copy template users stuff to here. 
    173178    my $template = Scrpbk::M::Person->retrieve( tag => 'template' ); 
    174     if ( $template ) { 
    175  
    176         my %holder_id_lkup = (); 
    177  
    178         foreach my $holder ( $template->holders ) { 
    179             # Create the holder and add to the lookup table. 
    180             my $new_holder = $holder->copy({ person => $person }); 
    181             $holder_id_lkup{ $holder->id } = $new_holder; 
    182         } 
    183  
    184         foreach my $scrap ( $template->scraps ) { 
    185             # Copy the scrap. 
    186             my %args = (); 
    187             $args{holder} = $holder_id_lkup{ $scrap->holder->id }  
    188             if $scrap->holder;  
    189  
    190             my $new_scrap = $scrap->copy 
    191                 ({ 
    192                     person => $person, 
    193                     %args 
    194                 }); 
    195         } 
    196  
    197          
    198     } else { 
    199         $c->log->info("You should create the template user to copy from."); 
     179    if ($template) { 
     180 
     181        my %holder_id_lkup = (); 
     182 
     183        foreach my $holder ( $template->holders ) { 
     184 
     185            # Create the holder and add to the lookup table. 
     186            my $new_holder = $holder->copy( { person => $person } ); 
     187            $holder_id_lkup{ $holder->id } = $new_holder; 
     188        } 
     189 
     190        foreach my $scrap ( $template->scraps ) { 
     191 
     192            # Copy the scrap. 
     193            my %args = (); 
     194            $args{holder} = $holder_id_lkup{ $scrap->holder->id } 
     195              if $scrap->holder; 
     196 
     197            my $new_scrap = $scrap->copy( 
     198                { 
     199                    person => $person, 
     200                    %args 
     201                } 
     202            ); 
     203        } 
     204 
     205    } 
     206    else { 
     207        $c->log->info("You should create the template user to copy from."); 
    200208    } 
    201209 
     
    211219    my $person = $c->stash->{person}; 
    212220 
    213     unless ( $person ) { 
    214        $c->stash->{fatal_error} = "Need a person to create a session."; 
    215        return $c->forward('/fatal_error'); 
     221    unless ($person) { 
     222        $c->stash->{fatal_error} = "Need a person to create a session."; 
     223        return $c->forward('/fatal_error'); 
    216224    } 
    217225 
    218226    # create the session. 
    219     my $session = Scrpbk::M::Session->create({ person => $person }); 
    220  
    221     unless ( $session ) { 
    222        $c->stash->{fatal_error} = "Could not create a session"; 
    223        return $c->forward('/fatal_error'); 
     227    my $session = Scrpbk::M::Session->create( { person => $person } ); 
     228 
     229    unless ($session) { 
     230        $c->stash->{fatal_error} = "Could not create a session"; 
     231        return $c->forward('/fatal_error'); 
    224232    } 
    225233 
    226234    # Put the session token onto a cookie. 
    227235    $c->stash->{session} = $session; 
    228     $c->res->cookies->{session} = { value   => $session->token, 
    229                                     expires => '+10y' }; 
     236    $c->res->cookies->{session} = { 
     237        value   => $session->token, 
     238        expires => '+10y' 
     239    }; 
    230240    return 1; 
    231241} 
     
    236246    my $session = $c->stash->{session}; 
    237247 
    238     unless ( $session ) { 
    239        $c->stash->{fatal_error} = "Could not find a session to delete."; 
    240        return $c->forward('/fatal_error'); 
     248    unless ($session) { 
     249        $c->stash->{fatal_error} = "Could not find a session to delete."; 
     250        return $c->forward('/fatal_error'); 
    241251    } 
    242252 
     
    253263sub forgottenpassword : Local { 
    254264    my ( $self, $c ) = @_; 
    255      
     265 
    256266    # If there is no form there is nothing to do. 
    257267    return unless $c->req->param('form_submitted'); 
     
    265275 
    266276    # Check that they are good. 
    267     if ( $email ) { 
    268         $person = Scrpbk::M::Person->retrieve( email => $email ); 
    269         push @messages, "Email not found - please check it." 
    270             unless $person; 
    271  
    272     } elsif ( $tag ) { 
    273         $person = Scrpbk::M::Person->retrieve( tag => $tag ); 
    274         push @messages, "Tag not found - please check it." 
    275             unless $person; 
    276  
    277     } else { 
    278         push @messages, "Please provide either an email or a tag."; 
     277    if ($email) { 
     278        $person = Scrpbk::M::Person->retrieve( email => $email ); 
     279        push @messages, "Email not found - please check it." 
     280          unless $person; 
     281 
     282    } 
     283    elsif ($tag) { 
     284        $person = Scrpbk::M::Person->retrieve( tag => $tag ); 
     285        push @messages, "Tag not found - please check it." 
     286          unless $person; 
     287 
     288    } 
     289    else { 
     290        push @messages, "Please provide either an email or a tag."; 
    279291    } 
    280292 
    281293    # If there was a problem then return. 
    282294    if ( scalar @messages ) { 
    283        $c->stash->{messages} = \@messages; 
    284         $c->stash->{details} = { email => $email, tag => $tag };                          
    285        return 0; 
     295        $c->stash->{messages} = \@messages; 
     296        $c->stash->{details} = { email => $email, tag => $tag }; 
     297        return 0; 
    286298    } 
    287299 
    288300    # We have a person - send a reminder. 
    289     $c->stash->{remind_person} = $person; 
     301    $c->stash->{remind_person} = $person; 
    290302    $c->stash->{email_template} = 'emails/password_reminder'; 
    291     $c->stash->{email_to} = $person->email; 
    292     $c->stash->{email_bcc} = 'scrpbk@ecclestoad.co.uk'; 
     303    $c->stash->{email_to}       = $person->email; 
     304    $c->stash->{email_bcc}      = 'scrpbk@ecclestoad.co.uk'; 
    293305    $c->forward("Scrpbk::V::Email"); 
    294306 
     
    305317    # Need someone logged in - otherwise redirect. 
    306318    return $c->forward('/redirect_to_login') 
    307        unless $person; 
     319      unless $person; 
    308320 
    309321    # Return if there is no form_submitted. 
     
    320332 
    321333    push @messages, "The old password was not correct." 
    322        unless $old_password eq $person->password; 
     334      unless $old_password eq $person->password; 
    323335 
    324336    push @messages, "The new passwords are different." 
    325        unless $new_password eq $new_password2; 
     337      unless $new_password eq $new_password2; 
    326338 
    327339    push @messages, "The new password must be between 6 and 20 characters" 
    328         unless length( $new_password ) <= 20 &&  
    329        length( $new_password ) >= 6; 
     340      unless length($new_password) <= 20 
     341      && length($new_password) >= 6; 
    330342 
    331343    return 1 if scalar @messages; 
    332344 
    333345    # Try to change the pasword. 
    334     $person->password( $new_password ); 
     346    $person->password($new_password); 
    335347    $person->update; 
    336348 
     
    339351} 
    340352 
    341  
    3423531; 
    343354 
  • trunk/lib/Scrpbk/C/Scrap.pm

    r2 r5  
    88sub auto : Private { 
    99    my ( $self, $c ) = @_; 
    10      
     10 
    1111    # Redirect to login unless we have a user. 
    1212    unless ( $c->stash->{person} ) { 
    13        $c->forward('/redirect_to_login'); 
    14        return 0; 
     13        $c->forward('/redirect_to_login'); 
     14        return 0; 
    1515    } 
    1616} 
     
    3131 
    3232    my $person = $c->stash->{person} || return 0; 
    33      
    34     my $scrap = Scrpbk::M::Scrap->retrieve 
    35         ( person => $person, 
    36           id     => $scrap_id ); 
    37      
     33 
     34    my $scrap = Scrpbk::M::Scrap->retrieve( 
     35        person => $person, 
     36        id     => $scrap_id 
     37    ); 
     38 
    3839    # Did we got a scrap. 
    39     unless ( $scrap ) { 
    40        $c->stash->{fatal_error} = "Scrap '$scrap_id' not found."; 
    41        return $c->forward('/fatal_error'); 
     40    unless ($scrap) { 
     41        $c->stash->{fatal_error} = "Scrap '$scrap_id' not found."; 
     42        return $c->forward('/fatal_error'); 
    4243    } 
    4344 
     
    7172    # return if needed. 
    7273    return $c->forward('/redirect_to_referer') 
    73        unless $scrap_id; 
    74  
    75     unless ( $holder_id ) { 
    76        $c->stash->{fatal_error} = "Could not determine which holder to use."; 
    77        return $c->forward('fatal_error'); 
     74      unless $scrap_id; 
     75 
     76    unless ($holder_id) { 
     77        $c->stash->{fatal_error} = "Could not determine which holder to use."; 
     78        return $c->forward('fatal_error'); 
    7879    } 
    7980 
    8081    # Check the rank is usable. 
    8182    unless ( $rank =~ m/^\d+$/ ) { 
    82        $c->stash->{fatal_error} = "Rank '$rank' is not usable."; 
    83        return $c->forward('/fatal_error'); 
     83        $c->stash->{fatal_error} = "Rank '$rank' is not usable."; 
     84        return $c->forward('/fatal_error'); 
    8485    } 
    8586 
    8687    # Get the scrap. 
    87     my $scrap = Scrpbk::M::Scrap->retrieve 
    88        ( id     => $scrap_id, 
    89          person => $person 
    90         ); 
    91      
     88    my $scrap = Scrpbk::M::Scrap->retrieve( 
     89        id     => $scrap_id, 
     90        person => $person 
     91    ); 
     92 
    9293    # Did we get a scrap. 
    93     unless ( $scrap ) { 
    94        $c->stash->{fatal_error} = "Scrap '$scrap_id' not found."; 
    95        return $c->forward('/fatal_error'); 
     94    unless ($scrap) { 
     95        $c->stash->{fatal_error} = "Scrap '$scrap_id' not found."; 
     96        return $c->forward('/fatal_error'); 
    9697    } 
    9798 
    9899    # Get the holder. 
    99     my $new_holder = Scrpbk::M::Holder->retrieve 
    100        ( id     => $holder_id, 
    101          person => $person, 
    102          ); 
     100    my $new_holder = Scrpbk::M::Holder->retrieve( 
     101        id     => $holder_id, 
     102        person => $person, 
     103    ); 
    103104 
    104105    # Did we get a holder. 
    105     unless ( $new_holder ) { 
    106        $c->stash->{fatal_error} = "Holder '$holder_id' not found."; 
    107        return $c->forward('/fatal_error'); 
    108     } 
    109      
     106    unless ($new_holder) { 
     107        $c->stash->{fatal_error} = "Holder '$holder_id' not found."; 
     108        return $c->forward('/fatal_error'); 
     109    } 
     110 
    110111    # Rerank the scraps in this holder. 
    111     my @scraps = Scrpbk::M::Scrap->search 
    112         ( holder => $new_holder, 
    113           {order_by => 'rank, id'} ); 
    114      
     112    my @scraps = Scrpbk::M::Scrap->search( 
     113        holder => $new_holder, 
     114        { order_by => 'rank, id' } 
     115    ); 
     116 
    115117    my $tmp_rank = 0; 
    116     foreach my $tmp_scrap ( @scraps ) { 
    117        $tmp_rank += 2; 
    118        $tmp_scrap->rank( $tmp_rank ); 
    119        $tmp_scrap->update; 
     118    foreach my $tmp_scrap (@scraps) { 
     119        $tmp_rank += 2; 
     120        $tmp_scrap->rank($tmp_rank); 
     121        $tmp_scrap->update; 
    120122    } 
    121123 
    122124    # Move the scrap to the new holder. 
    123     $scrap->holder( $new_holder ); 
    124     $scrap->rank( ($rank * 2) + 1 ); 
     125    $scrap->holder($new_holder); 
     126    $scrap->rank( ( $rank * 2 ) + 1 ); 
    125127    $scrap->update; 
    126128 
     
    141143 
    142144    if ( $scrap_id eq 'new' ) { 
    143         # Don't do anything. 
    144         $scrap = undef; 
    145     } elsif ( $scrap_id =~ m/^\d+$/ ) { 
    146         # Try to load the scrap. 
    147         $scrap = Scrpbk::M::Scrap->retrieve 
    148             ( id     => $scrap_id, 
    149               person => $person ); 
    150  
    151         unless ( $scrap ) { 
    152             # Error loading the scrap. 
    153             $c->stash->{fatal_error} = "Scrap '$scrap_id' not found."; 
    154             return $c->forward('/fatal_error'); 
    155         } 
    156     } else { 
    157         # Should not be here. 
    158         $c->stash->{fatal_error} = "Can't get the scrap '$scrap_id'."; 
    159         return $c->forward('/fatal_error'); 
     145 
     146        # Don't do anything. 
     147        $scrap = undef; 
     148    } 
     149    elsif ( $scrap_id =~ m/^\d+$/ ) { 
     150 
     151        # Try to load the scrap. 
     152        $scrap = Scrpbk::M::Scrap->retrieve( 
     153            id     => $scrap_id, 
     154            person => $person 
     155        ); 
     156 
     157        unless ($scrap) { 
     158 
     159            # Error loading the scrap. 
     160            $c->stash->{fatal_error} = "Scrap '$scrap_id' not found."; 
     161            return $c->forward('/fatal_error'); 
     162        } 
     163    } 
     164    else { 
     165 
     166        # Should not be here. 
     167        $c->stash->{fatal_error} = "Can't get the scrap '$scrap_id'."; 
     168        return $c->forward('/fatal_error'); 
    160169    } 
    161170 
    162171    # Put the scrap on the stash. 
    163172    $c->stash->{scrap} = $scrap; 
    164      
     173 
    165174    # Is there a form to do. 
    166175    return unless $c->req->param('form_submitted'); 
     
    178187    # Validate the inputs. 
    179188    push @messages, "The name is too long, must be no more than than 40 chars" 
    180        if length( $name ) > 40; 
     189      if length($name) > 40; 
    181190    push @messages, "The name is too short, must be at least 1 char" 
    182        if length( $name ) < 1; 
     191      if length($name) < 1; 
    183192    push @messages, "The note is too long, must be no more than than 1000 chars" 
    184        if length( $note ) > 1000; 
     193      if length($note) > 1000; 
    185194    push @messages, "The url is too long, must be no more than than 500 chars" 
    186        if length( $url ) > 500; 
     195      if length($url) > 500; 
    187196 
    188197    # Return if errors found. 
    189198    if ( scalar @messages ) { 
    190         $c->stash->{messages} = \@messages; 
    191         $c->stash->{new} = { name => $name, 
    192                              note => $note, 
    193                              url  => $url  }; 
    194         return 1 ; 
     199        $c->stash->{messages} = \@messages; 
     200        $c->stash->{new}      = { 
     201            name => $name, 
     202            note => $note, 
     203            url  => $url 
     204        }; 
     205        return 1; 
    195206    } 
    196207 
    197208    # Update or create the scrap. 
    198     if ( $scrap ) { 
    199         $scrap->set( name => $name, note => $note, url  => $url ); 
    200         $scrap->update; 
    201     } else { 
    202         $scrap = Scrpbk::M::Scrap->create 
    203             ({ person => $person, name => $name, note => $note, url  => $url }); 
     209    if ($scrap) { 
     210        $scrap->set( name => $name, note => $note, url => $url ); 
     211        $scrap->update; 
     212    } 
     213    else { 
     214        $scrap = 
     215          Scrpbk::M::Scrap->create( 
     216            { person => $person, name => $name, note => $note, url => $url } ); 
    204217    } 
    205218 
  • trunk/lib/Scrpbk/C/SearchEngine.pm

    r2 r5  
    33use strict; 
    44use base 'Catalyst::Base'; 
    5  
    65 
    76sub default : Private { 
     
    1110    # Validate the offset or set to zero. 
    1211    $offset = 0 unless defined $offset && $offset =~ m/^\d+$/; 
    13      
     12 
    1413    # Set up the variables to use in the sql. 
    15     my $number = 400; 
     14    my $number = 400; 
    1615 
    1716    # Get the persons' tags and place them on the template. 
    18     my @persons = Scrpbk::M::Person->search_list_tags 
    19        ( $number, $number * $offset ); 
     17    my @persons = 
     18      Scrpbk::M::Person->search_list_tags( $number, $number * $offset ); 
    2019 
    21     my @tags = map { $_-> tag } @persons; 
     20    my @tags = map { $_->tag } @persons; 
    2221 
    2322    $c->stash->{tags} = \@tags; 
     
    2827    $c->stash->{template}       = 'searchengine/tag_list'; 
    2928} 
    30  
    3129 
    3230=head1 NAME 
  • trunk/lib/Scrpbk/M/DBI.pm

    r2 r5  
    66 
    77my $db_name = $ENV{DB_NAME} || 'scrpbk'; 
    8 __PACKAGE__->connection("dbi:Pg:dbname=$db_name", '', '', { AutoCommit => 1 } ); 
    9  
     8__PACKAGE__->connection( "dbi:Pg:dbname=$db_name", '', '', 
     9    { AutoCommit => 1 } ); 
    1010 
    1111# Global sequence for all id numbers. 
    12 __PACKAGE__->sequence( 'global_id_sequence' ); 
     12__PACKAGE__->sequence('global_id_sequence'); 
    1313 
    1414sub create_token { 
    15     my @A = ( 'a'..'z', 'A'..'Z', 0..9 ); 
     15    my @A = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9 ); 
    1616    my $seq = ''; 
    17     $seq .= $A[ rand scalar @A ] for 1..40; 
     17    $seq .= $A[ rand scalar @A ] for 1 .. 40; 
    1818    return $seq; 
    1919} 
     
    21211; 
    2222 
    23  
  • trunk/lib/Scrpbk/M/Holder.pm

    r2 r5  
    1212__PACKAGE__->has_many( scraps => 'Scrpbk::M::Scrap' ); 
    1313 
    14  
    15 __PACKAGE__->add_trigger 
    16     ( before_create => sub { 
     14__PACKAGE__->add_trigger( 
     15    before_create => sub { 
    1716        my $self = shift; 
    1817 
    19        # Set some sensible defaults; 
    20        $self->col(  $self->col  || 1 ); 
    21        $self->rank( $self->rank || 1 ); 
     18        # Set some sensible defaults; 
     19        $self->col( $self->col   || 1 ); 
     20        $self->rank( $self->rank || 1 ); 
    2221 
    2322        return 1; 
    2423    } 
    25       ); 
    26  
     24); 
    2725 
    2826sub relocate { 
    2927    my $self = shift; 
    30     my $dir = shift; 
     28    my $dir = shift; 
    3129 
    3230    if ( $dir =~ m/^(up|down)$/ ) { 
    33         $self->relocate_vertically( $dir ); 
    34     } elsif ( $dir =~ m/^(left|right)$/ ) { 
    35         $self->relocate_horizontally( $dir ); 
    36     } else { die "Cannot move '$dir'"; } 
    37      
     31        $self->relocate_vertically($dir); 
     32    } 
     33    elsif ( $dir =~ m/^(left|right)$/ ) { 
     34        $self->relocate_horizontally($dir); 
     35    } 
     36    else { die "Cannot move '$dir'"; } 
     37 
    3838    return 1; 
    3939} 
     
    4141sub relocate_vertically { 
    4242    my $self = shift; 
    43     my $dir = shift; 
     43    my $dir = shift; 
    4444 
    4545    # Change the position of this holder. 
     
    5353sub relocate_horizontally { 
    5454    my $self = shift; 
    55     my $dir = shift; 
     55    my $dir = shift; 
    5656 
    5757    # What will the new col be? 
    58     my $change = $dir eq 'left' ? -1 : 1; 
     58    my $change = $dir eq 'left' ? -1 : 1; 
    5959    my $old_col = $self->col; 
    6060    my $new_col = $old_col + $change; 
     
    6262    # Check that the position can be changed. 
    6363    die "Cannot move to col '$new_col'" 
    64        if $new_col <= 0 || $new_col >= 3; 
     64      if $new_col <= 0 || $new_col >= 3; 
    6565 
    6666    # Change the position of this holder. 
    67     $self->col( $new_col ); 
    68     $self->rank( 0 ); 
     67    $self->col($new_col); 
     68    $self->rank(0); 
    6969    $self->update; 
    7070 
    7171  &nb