Skip to content

Instantly share code, notes, and snippets.

@ktat
Forked from S2/gist:faed4544940c63aad945
Last active August 29, 2015 14:22
Show Gist options
  • Save ktat/2ef7f2610576a917c06f to your computer and use it in GitHub Desktop.
Save ktat/2ef7f2610576a917c06f to your computer and use it in GitHub Desktop.
use base qw/Qudo::Worker/;
sub import{
my $class = shift;
if($class->split_process_from_initial_character()){
no strict 'refs';
my $package = $class;
*{"$package\::InitialLowerCase::ISA"} = [$package];
*{"$package\::InitialUpperCase::ISA"} = [$package];
*{"$package\::InitialNumber::ISA"} = [$package];
*{"$package\::get_splited_worker_classname"} = sub {
my ($class , $args )= @_;
my $c = Kuroneco->bootstrap();
my $dao = $c->dao('default');
my $media_id = $args->{media_id};
my $media = $dao->single('media' , {id => $media_id});
my $args_hash = {map{split "=" , $_ }split("&" , $args->{args})};
my $user_id = $args_hash->{$media->user_id_column_name};
my $initial_uesr_id = substr($user_id , 0 , 1);
if($initial_uesr_id =~ /[0-9]/){
return "$package\::InitialNumber";
}elsif($initial_uesr_id =~ /[a-z]/){
return "$package\::InitialLowerCase";
}elsif($initial_uesr_id =~ /[A-Z]/){
return "$package\::InitialUpperCase";
}{
die;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment